mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-11-04 07:32:59 +00:00 
			
		
		
		
	Compare commits
	
		
			96 Commits
		
	
	
		
			v1.20.4-1.
			...
			v1.20.1-1.
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					d24984c1d5 | ||
| 
						 | 
					8080dcdd9e | ||
| 
						 | 
					d7cea55e2a | ||
| 
						 | 
					9b2f974a81 | ||
| 
						 | 
					43770fa9bd | ||
| 
						 | 
					80c7a54ad4 | ||
| 
						 | 
					e57b6fede2 | ||
| 
						 | 
					34a2fd039f | ||
| 
						 | 
					3299d0e72a | ||
| 
						 | 
					b89e2615db | ||
| 
						 | 
					cdcd82679c | ||
| 
						 | 
					cdfa866760 | ||
| 
						 | 
					aa8078ddeb | ||
| 
						 | 
					7e53c19d74 | ||
| 
						 | 
					b7a8432cfb | ||
| 
						 | 
					356c8e8aeb | ||
| 
						 | 
					ed283155f7 | ||
| 
						 | 
					87dfad026e | ||
| 
						 | 
					bb97c465d9 | ||
| 
						 | 
					9484315d37 | ||
| 
						 | 
					be59f1a875 | ||
| 
						 | 
					bfb28b4710 | ||
| 
						 | 
					216f0adb3c | ||
| 
						 | 
					77af4bc213 | ||
| 
						 | 
					5abab982c7 | ||
| 
						 | 
					764e1aa332 | ||
| 
						 | 
					c47718b09d | ||
| 
						 | 
					08d4f91c8b | ||
| 
						 | 
					b9eac4e509 | ||
| 
						 | 
					dc3d8ea198 | ||
| 
						 | 
					cbe075b001 | ||
| 
						 | 
					ed0b156e05 | ||
| 
						 | 
					4dd0735066 | ||
| 
						 | 
					38e516d7c7 | ||
| 
						 | 
					70a31855ac | ||
| 
						 | 
					6c8e64ffcd | ||
| 
						 | 
					7285c32d58 | ||
| 
						 | 
					99c60ac54b | ||
| 
						 | 
					63e40cf3cb | ||
| 
						 | 
					1d45935a25 | ||
| 
						 | 
					f80373e7a2 | ||
| 
						 | 
					63185629b7 | ||
| 
						 | 
					4bfb9ac323 | ||
| 
						 | 
					5926b6c994 | ||
| 
						 | 
					f5ed43584d | ||
| 
						 | 
					d77f5f135f | ||
| 
						 | 
					7744d2663b | ||
| 
						 | 
					4566cb8273 | ||
| 
						 | 
					052e7a7ae5 | ||
| 
						 | 
					0895200681 | ||
| 
						 | 
					09d0f563b7 | ||
| 
						 | 
					e188f1d3fa | ||
| 
						 | 
					819a4f7231 | ||
| 
						 | 
					898cb2a95d | ||
| 
						 | 
					03a8f83191 | ||
| 
						 | 
					aef92c8ebc | ||
| 
						 | 
					571ea794a8 | ||
| 
						 | 
					e81af93043 | ||
| 
						 | 
					25b8a65c5c | ||
| 
						 | 
					e4236824d7 | ||
| 
						 | 
					cfd11ffa92 | ||
| 
						 | 
					ce133a5e66 | ||
| 
						 | 
					038fbc1ed1 | ||
| 
						 | 
					c582fb521c | ||
| 
						 | 
					af21792844 | ||
| 
						 | 
					9fbb1070ef | ||
| 
						 | 
					1944995c33 | ||
| 
						 | 
					ac851a795b | ||
| 
						 | 
					334761788a | ||
| 
						 | 
					5af3e15dd5 | ||
| 
						 | 
					209b1ddbf9 | ||
| 
						 | 
					0c9f9a8652 | ||
| 
						 | 
					862d92785e | ||
| 
						 | 
					d48b85d50c | ||
| 
						 | 
					4d619de357 | ||
| 
						 | 
					57c289f173 | ||
| 
						 | 
					f63f85921f | ||
| 
						 | 
					c7e49d1929 | ||
| 
						 | 
					d9b0cc7075 | ||
| 
						 | 
					1e214f329e | ||
| 
						 | 
					de930c8d09 | ||
| 
						 | 
					735e7ce09b | ||
| 
						 | 
					6e9799316a | ||
| 
						 | 
					4e90240922 | ||
| 
						 | 
					1a87d1bf45 | ||
| 
						 | 
					00e2e2bd2d | ||
| 
						 | 
					7c1f40031b | ||
| 
						 | 
					929debd382 | ||
| 
						 | 
					4980b7355d | ||
| 
						 | 
					925092add3 | ||
| 
						 | 
					550296edc5 | ||
| 
						 | 
					0771c4891b | ||
| 
						 | 
					776fa00b94 | ||
| 
						 | 
					03bb279206 | ||
| 
						 | 
					fabd77132d | ||
| 
						 | 
					95be0a25bf | 
							
								
								
									
										6
									
								
								.github/ISSUE_TEMPLATE/bug_report.yaml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.github/ISSUE_TEMPLATE/bug_report.yaml
									
									
									
									
										vendored
									
									
								
							@@ -8,10 +8,8 @@ body:
 | 
			
		||||
    label: Minecraft Version
 | 
			
		||||
    description: What version of Minecraft are you using?
 | 
			
		||||
    options:
 | 
			
		||||
      - 1.16.x
 | 
			
		||||
      - 1.18.x
 | 
			
		||||
      - 1.19.x
 | 
			
		||||
      - 1.20.x
 | 
			
		||||
      - 1.20.1
 | 
			
		||||
      - 1.21.x
 | 
			
		||||
  validations:
 | 
			
		||||
    required: true
 | 
			
		||||
- type: input
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								.github/workflows/main-ci.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										18
									
								
								.github/workflows/main-ci.yml
									
									
									
									
										vendored
									
									
								
							@@ -58,13 +58,13 @@ jobs:
 | 
			
		||||
        find projects/forge/build/libs projects/fabric/build/libs -type f -regex '.*[0-9.]+\(-SNAPSHOT\)?\.jar$' -exec bash -c 'cp {} "jars/$(basename {} .jar)-$(git rev-parse HEAD).jar"' \;
 | 
			
		||||
 | 
			
		||||
    - name: 📤 Upload Jar
 | 
			
		||||
      uses: actions/upload-artifact@v3
 | 
			
		||||
      uses: actions/upload-artifact@v4
 | 
			
		||||
      with:
 | 
			
		||||
        name: CC-Tweaked
 | 
			
		||||
        path: ./jars
 | 
			
		||||
 | 
			
		||||
    - name: 📤 Upload coverage
 | 
			
		||||
      uses: codecov/codecov-action@v3
 | 
			
		||||
      uses: codecov/codecov-action@v4
 | 
			
		||||
 | 
			
		||||
  build-core:
 | 
			
		||||
    strategy:
 | 
			
		||||
@@ -81,24 +81,28 @@ jobs:
 | 
			
		||||
    runs-on: ${{ matrix.uses }}
 | 
			
		||||
 | 
			
		||||
    steps:
 | 
			
		||||
    - name: Clone repository
 | 
			
		||||
    - name: 📥 Clone repository
 | 
			
		||||
      uses: actions/checkout@v4
 | 
			
		||||
 | 
			
		||||
    - name: Set up Java
 | 
			
		||||
    - name: 📥 Set up Java
 | 
			
		||||
      uses: actions/setup-java@v4
 | 
			
		||||
      with:
 | 
			
		||||
        java-version: 17
 | 
			
		||||
        distribution: 'temurin'
 | 
			
		||||
 | 
			
		||||
    - name: Setup Gradle
 | 
			
		||||
    - name: 📥 Setup Gradle
 | 
			
		||||
      uses: gradle/actions/setup-gradle@v3
 | 
			
		||||
      with:
 | 
			
		||||
        cache-read-only: ${{ !startsWith(github.ref, 'refs/heads/mc-') }}
 | 
			
		||||
 | 
			
		||||
    - name: Run tests
 | 
			
		||||
    - name: ⚒️ Build
 | 
			
		||||
      run: |
 | 
			
		||||
        ./gradlew --configure-on-demand :core:assemble
 | 
			
		||||
 | 
			
		||||
    - name: 🧪 Run tests
 | 
			
		||||
      run: |
 | 
			
		||||
        ./gradlew --configure-on-demand :core:test
 | 
			
		||||
 | 
			
		||||
    - name: Parse test reports
 | 
			
		||||
    - name: 🧪 Parse test reports
 | 
			
		||||
      run: python3 ./tools/parse-reports.py
 | 
			
		||||
      if: ${{ failure() }}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										19
									
								
								.github/workflows/make-doc.sh
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										19
									
								
								.github/workflows/make-doc.sh
									
									
									
									
										vendored
									
									
								
							@@ -1,19 +0,0 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
set -eu
 | 
			
		||||
 | 
			
		||||
DEST="${GITHUB_REF#refs/*/}"
 | 
			
		||||
echo "Uploading docs to https://tweaked.cc/$DEST"
 | 
			
		||||
 | 
			
		||||
# Setup ssh key
 | 
			
		||||
mkdir -p "$HOME/.ssh/"
 | 
			
		||||
echo "$SSH_KEY" > "$HOME/.ssh/key"
 | 
			
		||||
chmod 600 "$HOME/.ssh/key"
 | 
			
		||||
 | 
			
		||||
# And upload
 | 
			
		||||
rsync -avc -e "ssh -i $HOME/.ssh/key -o StrictHostKeyChecking=no -p $SSH_PORT" \
 | 
			
		||||
      "$GITHUB_WORKSPACE/projects/web/build/site/" \
 | 
			
		||||
      "$SSH_USER@$SSH_HOST:/$DEST"
 | 
			
		||||
rsync -avc -e "ssh -i $HOME/.ssh/key -o StrictHostKeyChecking=no -p $SSH_PORT" \
 | 
			
		||||
      "$GITHUB_WORKSPACE/projects/common-api/build/docs/javadoc/" \
 | 
			
		||||
      "$SSH_USER@$SSH_HOST:/$DEST/javadoc"
 | 
			
		||||
							
								
								
									
										28
									
								
								.github/workflows/make-doc.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										28
									
								
								.github/workflows/make-doc.yml
									
									
									
									
										vendored
									
									
								
							@@ -3,8 +3,7 @@ name: Build documentation
 | 
			
		||||
on:
 | 
			
		||||
  push:
 | 
			
		||||
    branches:
 | 
			
		||||
    - mc-1.19.x
 | 
			
		||||
    - mc-1.20.x
 | 
			
		||||
    - mc-*
 | 
			
		||||
 | 
			
		||||
jobs:
 | 
			
		||||
  make_doc:
 | 
			
		||||
@@ -12,30 +11,25 @@ jobs:
 | 
			
		||||
    runs-on: ubuntu-latest
 | 
			
		||||
 | 
			
		||||
    steps:
 | 
			
		||||
    - name: Clone repository
 | 
			
		||||
    - name: 📥 Clone repository
 | 
			
		||||
      uses: actions/checkout@v4
 | 
			
		||||
 | 
			
		||||
    - name: Set up Java
 | 
			
		||||
    - name: 📥 Set up Java
 | 
			
		||||
      uses: actions/setup-java@v4
 | 
			
		||||
      with:
 | 
			
		||||
        java-version: 17
 | 
			
		||||
        distribution: 'temurin'
 | 
			
		||||
 | 
			
		||||
    - name: Setup Gradle
 | 
			
		||||
    - name: 📥 Setup Gradle
 | 
			
		||||
      uses: gradle/actions/setup-gradle@v3
 | 
			
		||||
      with:
 | 
			
		||||
        cache-read-only: ${{ !startsWith(github.ref, 'refs/heads/mc-') }}
 | 
			
		||||
 | 
			
		||||
    - name: Build with Gradle
 | 
			
		||||
      run: ./gradlew compileJava --no-daemon || ./gradlew compileJava --no-daemon
 | 
			
		||||
    - name: ⚒️ Generate documentation
 | 
			
		||||
      run: ./gradlew docWebsite --no-daemon
 | 
			
		||||
 | 
			
		||||
    - name: Generate documentation
 | 
			
		||||
      run: ./gradlew docWebsite :common-api:javadoc  --no-daemon
 | 
			
		||||
 | 
			
		||||
    - name: Upload documentation
 | 
			
		||||
      run: .github/workflows/make-doc.sh 2> /dev/null
 | 
			
		||||
      env:
 | 
			
		||||
        SSH_KEY:  ${{ secrets.SSH_KEY  }}
 | 
			
		||||
        SSH_USER: ${{ secrets.SSH_USER }}
 | 
			
		||||
        SSH_HOST: ${{ secrets.SSH_HOST }}
 | 
			
		||||
        SSH_PORT: ${{ secrets.SSH_PORT }}
 | 
			
		||||
    - name: 📤 Upload Jar
 | 
			
		||||
      uses: actions/upload-artifact@v4
 | 
			
		||||
      with:
 | 
			
		||||
        name: Documentation
 | 
			
		||||
        path: ./projects/web/build/site/
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										26
									
								
								.gitpod.yml
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								.gitpod.yml
									
									
									
									
									
								
							@@ -1,26 +0,0 @@
 | 
			
		||||
# SPDX-FileCopyrightText: 2021 The CC: Tweaked Developers
 | 
			
		||||
#
 | 
			
		||||
# SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
image:
 | 
			
		||||
  file: config/gitpod/Dockerfile
 | 
			
		||||
 | 
			
		||||
ports:
 | 
			
		||||
  - port: 25565
 | 
			
		||||
    onOpen: notify
 | 
			
		||||
 | 
			
		||||
vscode:
 | 
			
		||||
  extensions:
 | 
			
		||||
    - eamodio.gitlens
 | 
			
		||||
    - github.vscode-pull-request-github
 | 
			
		||||
    - ms-azuretools.vscode-docker
 | 
			
		||||
    - redhat.java
 | 
			
		||||
    - richardwillis.vscode-gradle
 | 
			
		||||
    - vscjava.vscode-java-debug
 | 
			
		||||
    - vscode.github
 | 
			
		||||
 | 
			
		||||
tasks:
 | 
			
		||||
  - name: Setup pre-commit hool
 | 
			
		||||
    init: pre-commit install --allow-missing-config
 | 
			
		||||
  - name: Install npm packages
 | 
			
		||||
    init: npm ci
 | 
			
		||||
@@ -27,7 +27,7 @@ repos:
 | 
			
		||||
    exclude: "^(.*\\.(bat)|LICENSE)$"
 | 
			
		||||
 | 
			
		||||
- repo: https://github.com/fsfe/reuse-tool
 | 
			
		||||
  rev: v2.1.0
 | 
			
		||||
  rev: v4.0.3
 | 
			
		||||
  hooks:
 | 
			
		||||
  - id: reuse
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										100
									
								
								.reuse/dep5
									
									
									
									
									
								
							
							
						
						
									
										100
									
								
								.reuse/dep5
									
									
									
									
									
								
							@@ -1,100 +0,0 @@
 | 
			
		||||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
 | 
			
		||||
Source: https://github.com/cc-tweaked/cc-tweaked
 | 
			
		||||
Upstream-Name: CC: Tweaked
 | 
			
		||||
Upstream-Contact: Jonathan Coates <git@squiddev.cc>
 | 
			
		||||
 | 
			
		||||
Files:
 | 
			
		||||
  projects/common/src/main/resources/assets/computercraft/sounds.json
 | 
			
		||||
  projects/common/src/main/resources/assets/computercraft/sounds/empty.ogg
 | 
			
		||||
  projects/common/src/testMod/resources/data/cctest/computercraft/turtle_upgrades/*
 | 
			
		||||
  projects/common/src/testMod/resources/data/cctest/structures/*
 | 
			
		||||
  projects/fabric/src/generated/*
 | 
			
		||||
  projects/forge/src/generated/*
 | 
			
		||||
  projects/web/src/htmlTransform/export/index.json
 | 
			
		||||
  projects/web/src/htmlTransform/export/items/minecraft/*
 | 
			
		||||
Comment: Generated/data files are CC0.
 | 
			
		||||
Copyright: The CC: Tweaked Developers
 | 
			
		||||
License: CC0-1.0
 | 
			
		||||
 | 
			
		||||
Files:
 | 
			
		||||
  doc/images/*
 | 
			
		||||
  package.json
 | 
			
		||||
  package-lock.json
 | 
			
		||||
  projects/common/src/client/resources/computercraft-client.mixins.json
 | 
			
		||||
  projects/common/src/main/resources/assets/minecraft/shaders/core/computercraft/monitor_tbo.json
 | 
			
		||||
  projects/common/src/main/resources/computercraft.mixins.json
 | 
			
		||||
  projects/common/src/testMod/resources/computercraft-gametest.mixins.json
 | 
			
		||||
  projects/common/src/testMod/resources/data/computercraft/loot_tables/treasure_disk.json
 | 
			
		||||
  projects/common/src/testMod/resources/pack.mcmeta
 | 
			
		||||
  projects/core/src/main/resources/data/computercraft/lua/rom/modules/command/.ignoreme
 | 
			
		||||
  projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/.ignoreme
 | 
			
		||||
  projects/core/src/main/resources/data/computercraft/lua/rom/modules/turtle/.ignoreme
 | 
			
		||||
  projects/core/src/main/resources/data/computercraft/lua/rom/motd.txt
 | 
			
		||||
  projects/fabric-api/src/main/modJson/fabric.mod.json
 | 
			
		||||
  projects/fabric/src/client/resources/computercraft-client.fabric.mixins.json
 | 
			
		||||
  projects/fabric/src/main/resources/computercraft.fabric.mixins.json
 | 
			
		||||
  projects/fabric/src/main/resources/fabric.mod.json
 | 
			
		||||
  projects/fabric/src/testMod/resources/computercraft-gametest.fabric.mixins.json
 | 
			
		||||
  projects/fabric/src/testMod/resources/fabric.mod.json
 | 
			
		||||
  projects/forge/src/client/resources/computercraft-client.forge.mixins.json
 | 
			
		||||
  projects/web/src/frontend/mount/.settings
 | 
			
		||||
  projects/web/src/frontend/mount/example.nfp
 | 
			
		||||
  projects/web/src/frontend/mount/example.nft
 | 
			
		||||
  projects/web/src/frontend/mount/expr_template.lua
 | 
			
		||||
  projects/web/tsconfig.json
 | 
			
		||||
Comment: Several assets where it's inconvenient to create a .license file.
 | 
			
		||||
Copyright: The CC: Tweaked Developers
 | 
			
		||||
License: MPL-2.0
 | 
			
		||||
 | 
			
		||||
Files:
 | 
			
		||||
  doc/logo.png
 | 
			
		||||
  doc/logo-darkmode.png
 | 
			
		||||
  projects/common/src/main/resources/assets/computercraft/models/*
 | 
			
		||||
  projects/common/src/main/resources/assets/computercraft/textures/*
 | 
			
		||||
  projects/common/src/main/resources/pack.mcmeta
 | 
			
		||||
  projects/common/src/main/resources/pack.png
 | 
			
		||||
  projects/core/src/main/resources/assets/computercraft/textures/gui/term_font.png
 | 
			
		||||
  projects/core/src/main/resources/data/computercraft/lua/rom/autorun/.ignoreme
 | 
			
		||||
  projects/core/src/main/resources/data/computercraft/lua/rom/help/*
 | 
			
		||||
  projects/core/src/main/resources/data/computercraft/lua/rom/programs/fun/advanced/levels/*
 | 
			
		||||
  projects/web/src/htmlTransform/export/items/computercraft/*
 | 
			
		||||
Comment: Bulk-license original assets as CCPL.
 | 
			
		||||
Copyright: 2011 Daniel Ratcliffe
 | 
			
		||||
License: LicenseRef-CCPL
 | 
			
		||||
 | 
			
		||||
Files:
 | 
			
		||||
  projects/common/src/main/resources/assets/computercraft/lang/cs_cz.json
 | 
			
		||||
  projects/common/src/main/resources/assets/computercraft/lang/ko_kr.json
 | 
			
		||||
  projects/common/src/main/resources/assets/computercraft/lang/pl_pl.json
 | 
			
		||||
  projects/common/src/main/resources/assets/computercraft/lang/pt_br.json
 | 
			
		||||
  projects/common/src/main/resources/assets/computercraft/lang/ru_ru.json
 | 
			
		||||
  projects/common/src/main/resources/assets/computercraft/lang/uk_ua.json
 | 
			
		||||
  projects/common/src/main/resources/assets/computercraft/lang/zh_cn.json
 | 
			
		||||
Comment: Community-contributed license files
 | 
			
		||||
Copyright: 2017 The CC: Tweaked Developers
 | 
			
		||||
License: LicenseRef-CCPL
 | 
			
		||||
 | 
			
		||||
Files:
 | 
			
		||||
  projects/common/src/main/resources/assets/computercraft/lang/*
 | 
			
		||||
Comment: Community-contributed license files
 | 
			
		||||
Copyright: 2017 The CC: Tweaked Developers
 | 
			
		||||
License: MPL-2.0
 | 
			
		||||
 | 
			
		||||
Files:
 | 
			
		||||
  .github/*
 | 
			
		||||
Comment:
 | 
			
		||||
  GitHub build scripts are CC0. While we could add a header to each file,
 | 
			
		||||
  it's unclear if it will break actions or issue templates in some way.
 | 
			
		||||
Copyright: Jonathan Coates <git@squiddev.cc>
 | 
			
		||||
License: CC0-1.0
 | 
			
		||||
 | 
			
		||||
Files:
 | 
			
		||||
  gradle/wrapper/*
 | 
			
		||||
  gradlew
 | 
			
		||||
  gradlew.bat
 | 
			
		||||
Copyright: Gradle Inc
 | 
			
		||||
License: Apache-2.0
 | 
			
		||||
 | 
			
		||||
Files: projects/core/src/test/resources/test-rom/data/json-parsing/*
 | 
			
		||||
Copyright: 2016 Nicolas Seriot
 | 
			
		||||
License: MIT
 | 
			
		||||
@@ -12,7 +12,6 @@ If you've any other questions, [just ask the community][community] or [open an i
 | 
			
		||||
 | 
			
		||||
## Table of Contents
 | 
			
		||||
 - [Reporting issues](#reporting-issues)
 | 
			
		||||
 - [Translations](#translations)
 | 
			
		||||
 - [Setting up a development environment](#setting-up-a-development-environment)
 | 
			
		||||
 - [Developing CC: Tweaked](#developing-cc-tweaked)
 | 
			
		||||
 - [Writing documentation](#writing-documentation)
 | 
			
		||||
@@ -21,17 +20,13 @@ If you've any other questions, [just ask the community][community] or [open an i
 | 
			
		||||
If you have a bug, suggestion, or other feedback, the best thing to do is [file an issue][new-issue]. When doing so, do
 | 
			
		||||
use the issue templates - they provide a useful hint on what information to provide.
 | 
			
		||||
 | 
			
		||||
## Translations
 | 
			
		||||
Translations are managed through [Weblate], an online interface for managing language strings. This is synced
 | 
			
		||||
automatically with GitHub, so please don't submit PRs adding/changing translations!
 | 
			
		||||
 | 
			
		||||
## Setting up a development environment
 | 
			
		||||
In order to develop CC: Tweaked, you'll need to download the source code and then run it.
 | 
			
		||||
 | 
			
		||||
 - Make sure you've got the following software installed:
 | 
			
		||||
   - Java Development Kit (JDK) installed. This can be downloaded from [Adoptium].
 | 
			
		||||
   - Java Development Kit 17 (JDK). This can be downloaded from [Adoptium].
 | 
			
		||||
   - [Git](https://git-scm.com/).
 | 
			
		||||
   - If you want to work on documentation, [NodeJS][node].
 | 
			
		||||
   - [NodeJS 20 or later][node].
 | 
			
		||||
 | 
			
		||||
 - Download CC: Tweaked's source code:
 | 
			
		||||
   ```
 | 
			
		||||
@@ -101,7 +96,6 @@ about how you can build on that until you've covered everything!
 | 
			
		||||
[community]: README.md#community "Get in touch with the community."
 | 
			
		||||
[Adoptium]: https://adoptium.net/temurin/releases?version=17 "Download OpenJDK 17"
 | 
			
		||||
[illuaminate]: https://github.com/SquidDev/illuaminate/ "Illuaminate on GitHub"
 | 
			
		||||
[weblate]: https://i18n.tweaked.cc/projects/cc-tweaked/minecraft/ "CC: Tweaked weblate instance"
 | 
			
		||||
[docs]: https://tweaked.cc/ "CC: Tweaked documentation"
 | 
			
		||||
[ldoc]: http://stevedonovan.github.io/ldoc/ "ldoc, a Lua documentation generator."
 | 
			
		||||
[mc-test]: https://www.youtube.com/watch?v=vXaWOJTCYNg
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										16
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								README.md
									
									
									
									
									
								
							@@ -26,8 +26,9 @@ developing the mod, [check out the instructions here](CONTRIBUTING.md#developing
 | 
			
		||||
 | 
			
		||||
## Community
 | 
			
		||||
If you need help getting started with CC: Tweaked, want to show off your latest project, or just want to chat about
 | 
			
		||||
ComputerCraft, do check out our [forum] and [GitHub discussions page][GitHub discussions]! There's also a fairly
 | 
			
		||||
populated, albeit quiet [IRC channel][irc], if that's more your cup of tea.
 | 
			
		||||
ComputerCraft, do check out our [GitHub discussions page][GitHub discussions]! There's also a fairly populated,
 | 
			
		||||
albeit quiet IRC channel on [EsperNet], if that's more your cup of tea. You can join `#computercraft` through your
 | 
			
		||||
desktop client, or online using [KiwiIRC].
 | 
			
		||||
 | 
			
		||||
We also host fairly comprehensive documentation at [tweaked.cc](https://tweaked.cc/ "The CC: Tweaked website").
 | 
			
		||||
 | 
			
		||||
@@ -39,7 +40,7 @@ on is present.
 | 
			
		||||
```groovy
 | 
			
		||||
repositories {
 | 
			
		||||
  maven {
 | 
			
		||||
    url "https://squiddev.cc/maven/"
 | 
			
		||||
    url "https://maven.squiddev.cc"
 | 
			
		||||
    content {
 | 
			
		||||
      includeGroup("cc.tweaked")
 | 
			
		||||
    }
 | 
			
		||||
@@ -51,8 +52,9 @@ dependencies {
 | 
			
		||||
  compileOnly("cc.tweaked:cc-tweaked-$mcVersion-common-api:$cctVersion")
 | 
			
		||||
 | 
			
		||||
  // Forge Gradle
 | 
			
		||||
  compileOnly("cc.tweaked:cc-tweaked-$mcVersion-forge-api:$cctVersion")
 | 
			
		||||
  runtimeOnly("cc.tweaked:cc-tweaked-$mcVersion-forge:$cctVersion")
 | 
			
		||||
  compileOnly("cc.tweaked:cc-tweaked-$mcVersion-core-api:$cctVersion")
 | 
			
		||||
  compileOnly(fg.deobf("cc.tweaked:cc-tweaked-$mcVersion-forge-api:$cctVersion"))
 | 
			
		||||
  runtimeOnly(fg.deobf("cc.tweaked:cc-tweaked-$mcVersion-forge:$cctVersion"))
 | 
			
		||||
 | 
			
		||||
  // Fabric Loom
 | 
			
		||||
  modCompileOnly("cc.tweaked:cc-tweaked-$mcVersion-fabric-api:$cctVersion")
 | 
			
		||||
@@ -85,6 +87,6 @@ the generated documentation [can be browsed online](https://tweaked.cc/javadoc/)
 | 
			
		||||
[modrinth]: https://modrinth.com/mod/gu7yAYhd "Download CC: Tweaked from Modrinth"
 | 
			
		||||
[Minecraft Forge]: https://files.minecraftforge.net/ "Download Minecraft Forge."
 | 
			
		||||
[Fabric]: https://fabricmc.net/use/installer/ "Download Fabric."
 | 
			
		||||
[forum]: https://forums.computercraft.cc/
 | 
			
		||||
[GitHub Discussions]: https://github.com/cc-tweaked/CC-Tweaked/discussions
 | 
			
		||||
[IRC]: https://webchat.esper.net/?channels=computercraft "#computercraft on EsperNet"
 | 
			
		||||
[EsperNet]: https://www.esper.net/
 | 
			
		||||
[KiwiIRC]: https://kiwiirc.com/nextclient/#irc://irc.esper.net:+6697/#computercraft "#computercraft on EsperNet"
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										110
									
								
								REUSE.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								REUSE.toml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,110 @@
 | 
			
		||||
# SPDX-FileCopyrightText: 2017 The CC: Tweaked Developers
 | 
			
		||||
#
 | 
			
		||||
# SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
version = 1
 | 
			
		||||
SPDX-PackageName = "CC: Tweaked"
 | 
			
		||||
SPDX-PackageSupplier = "Jonathan Coates <git@squiddev.cc>"
 | 
			
		||||
SPDX-PackageDownloadLocation = "https://github.com/cc-tweaked/cc-tweaked"
 | 
			
		||||
 | 
			
		||||
[[annotations]]
 | 
			
		||||
# Generated/data files are CC0.
 | 
			
		||||
SPDX-FileCopyrightText = "The CC: Tweaked Developers"
 | 
			
		||||
SPDX-License-Identifier = "CC0-1.0"
 | 
			
		||||
path = [
 | 
			
		||||
    "gradle/gradle-daemon-jvm.properties",
 | 
			
		||||
    "projects/common/src/main/resources/assets/computercraft/sounds.json",
 | 
			
		||||
    "projects/common/src/main/resources/assets/computercraft/sounds/empty.ogg",
 | 
			
		||||
    "projects/common/src/testMod/resources/data/cctest/computercraft/turtle_upgrades/**",
 | 
			
		||||
    "projects/common/src/testMod/resources/data/cctest/structures/**",
 | 
			
		||||
    "projects/**/src/generated/**",
 | 
			
		||||
    "projects/web/src/htmlTransform/export/index.json",
 | 
			
		||||
    "projects/web/src/htmlTransform/export/items/minecraft/**",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[annotations]]
 | 
			
		||||
# Several assets where it's inconvenient to create a .license file.
 | 
			
		||||
SPDX-FileCopyrightText = "The CC: Tweaked Developers"
 | 
			
		||||
SPDX-License-Identifier = "MPL-2.0"
 | 
			
		||||
path = [
 | 
			
		||||
    "doc/images/**",
 | 
			
		||||
    "package.json",
 | 
			
		||||
    "package-lock.json",
 | 
			
		||||
    "projects/common/src/client/resources/computercraft-client.mixins.json",
 | 
			
		||||
    "projects/common/src/main/resources/assets/minecraft/shaders/core/computercraft/monitor_tbo.json",
 | 
			
		||||
    "projects/common/src/main/resources/computercraft.mixins.json",
 | 
			
		||||
    "projects/common/src/testMod/resources/computercraft-gametest.mixins.json",
 | 
			
		||||
    "projects/common/src/testMod/resources/data/computercraft/loot_tables/treasure_disk.json",
 | 
			
		||||
    "projects/common/src/testMod/resources/pack.mcmeta",
 | 
			
		||||
    "projects/core/src/main/resources/data/computercraft/lua/rom/modules/command/.ignoreme",
 | 
			
		||||
    "projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/.ignoreme",
 | 
			
		||||
    "projects/core/src/main/resources/data/computercraft/lua/rom/modules/turtle/.ignoreme",
 | 
			
		||||
    "projects/core/src/main/resources/data/computercraft/lua/rom/motd.txt",
 | 
			
		||||
    "projects/fabric-api/src/main/modJson/fabric.mod.json",
 | 
			
		||||
    "projects/fabric/src/client/resources/computercraft-client.fabric.mixins.json",
 | 
			
		||||
    "projects/fabric/src/main/resources/computercraft.fabric.mixins.json",
 | 
			
		||||
    "projects/fabric/src/main/resources/fabric.mod.json",
 | 
			
		||||
    "projects/fabric/src/testMod/resources/computercraft-gametest.fabric.mixins.json",
 | 
			
		||||
    "projects/fabric/src/testMod/resources/fabric.mod.json",
 | 
			
		||||
    "projects/forge/src/client/resources/computercraft-client.forge.mixins.json",
 | 
			
		||||
    "projects/web/src/frontend/mount/.settings",
 | 
			
		||||
    "projects/web/src/frontend/mount/example.nfp",
 | 
			
		||||
    "projects/web/src/frontend/mount/example.nft",
 | 
			
		||||
    "projects/web/src/frontend/mount/expr_template.lua",
 | 
			
		||||
    "projects/web/tsconfig.json",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[annotations]]
 | 
			
		||||
# Bulk-license original assets as CCPL.
 | 
			
		||||
SPDX-FileCopyrightText = "2011 Daniel Ratcliffe"
 | 
			
		||||
SPDX-License-Identifier = "LicenseRef-CCPL"
 | 
			
		||||
path = [
 | 
			
		||||
    "doc/logo.png",
 | 
			
		||||
    "doc/logo-darkmode.png",
 | 
			
		||||
    "projects/common/src/main/resources/assets/computercraft/models/**",
 | 
			
		||||
    "projects/common/src/main/resources/assets/computercraft/textures/**",
 | 
			
		||||
    "projects/common/src/main/resources/pack.mcmeta",
 | 
			
		||||
    "projects/common/src/main/resources/pack.png",
 | 
			
		||||
    "projects/core/src/main/resources/assets/computercraft/textures/gui/term_font.png",
 | 
			
		||||
    "projects/core/src/main/resources/data/computercraft/lua/rom/autorun/.ignoreme",
 | 
			
		||||
    "projects/core/src/main/resources/data/computercraft/lua/rom/help/**",
 | 
			
		||||
    "projects/core/src/main/resources/data/computercraft/lua/rom/programs/fun/advanced/levels/**",
 | 
			
		||||
    "projects/web/src/htmlTransform/export/items/computercraft/**",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[annotations]]
 | 
			
		||||
# Community-contributed license files
 | 
			
		||||
SPDX-FileCopyrightText = "2017 The CC: Tweaked Developers"
 | 
			
		||||
SPDX-License-Identifier = "LicenseRef-CCPL"
 | 
			
		||||
path = [
 | 
			
		||||
    "projects/common/src/main/resources/assets/computercraft/lang/cs_cz.json",
 | 
			
		||||
    "projects/common/src/main/resources/assets/computercraft/lang/ko_kr.json",
 | 
			
		||||
    "projects/common/src/main/resources/assets/computercraft/lang/pl_pl.json",
 | 
			
		||||
    "projects/common/src/main/resources/assets/computercraft/lang/pt_br.json",
 | 
			
		||||
    "projects/common/src/main/resources/assets/computercraft/lang/ru_ru.json",
 | 
			
		||||
    "projects/common/src/main/resources/assets/computercraft/lang/uk_ua.json",
 | 
			
		||||
    "projects/common/src/main/resources/assets/computercraft/lang/zh_cn.json",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[annotations]]
 | 
			
		||||
# Community-contributed license files
 | 
			
		||||
SPDX-FileCopyrightText = "2017 The CC: Tweaked Developers"
 | 
			
		||||
SPDX-License-Identifier = "MPL-2.0"
 | 
			
		||||
path = "projects/common/src/main/resources/assets/computercraft/lang/**"
 | 
			
		||||
 | 
			
		||||
[[annotations]]
 | 
			
		||||
# GitHub build scripts are CC0. While we could add a header to each file,
 | 
			
		||||
# it's unclear if it will break actions or issue templates in some way.
 | 
			
		||||
SPDX-FileCopyrightText = "Jonathan Coates <git@squiddev.cc>"
 | 
			
		||||
SPDX-License-Identifier = "CC0-1.0"
 | 
			
		||||
path = ".github/**"
 | 
			
		||||
 | 
			
		||||
[[annotations]]
 | 
			
		||||
path = ["gradle/wrapper/**"]
 | 
			
		||||
SPDX-FileCopyrightText = "Gradle Inc"
 | 
			
		||||
SPDX-License-Identifier = "Apache-2.0"
 | 
			
		||||
 | 
			
		||||
[[annotations]]
 | 
			
		||||
path = "projects/core/src/test/resources/test-rom/data/json-parsing/**"
 | 
			
		||||
SPDX-FileCopyrightText = "2016 Nicolas Seriot"
 | 
			
		||||
SPDX-License-Identifier = "MIT"
 | 
			
		||||
@@ -5,9 +5,8 @@
 | 
			
		||||
import cc.tweaked.gradle.JUnitExt
 | 
			
		||||
import net.fabricmc.loom.api.LoomGradleExtensionAPI
 | 
			
		||||
import net.fabricmc.loom.util.gradle.SourceSetHelper
 | 
			
		||||
import org.jetbrains.gradle.ext.compiler
 | 
			
		||||
import org.jetbrains.gradle.ext.runConfigurations
 | 
			
		||||
import org.jetbrains.gradle.ext.settings
 | 
			
		||||
import org.jetbrains.gradle.ext.*
 | 
			
		||||
import org.jetbrains.gradle.ext.Application
 | 
			
		||||
 | 
			
		||||
plugins {
 | 
			
		||||
    publishing
 | 
			
		||||
@@ -86,6 +85,19 @@ idea.project.settings.runConfigurations {
 | 
			
		||||
        moduleName = "${idea.project.name}.forge.test"
 | 
			
		||||
        packageName = ""
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    register<Application>("Standalone") {
 | 
			
		||||
        moduleName = "${idea.project.name}.standalone.main"
 | 
			
		||||
        mainClass = "cc.tweaked.standalone.Main"
 | 
			
		||||
        programParameters = "--resources=projects/core/src/main/resources --term=80x30 --allow-local-domains"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Build with the IntelliJ, rather than through Gradle. This may require setting the "Compiler Output" option in
 | 
			
		||||
// "Project Structure".
 | 
			
		||||
idea.project.settings.delegateActions {
 | 
			
		||||
    delegateBuildRunToGradle = false
 | 
			
		||||
    testRunner = ActionDelegationConfig.TestRunner.PLATFORM
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
idea.project.settings.compiler.javac {
 | 
			
		||||
 
 | 
			
		||||
@@ -14,14 +14,18 @@ repositories {
 | 
			
		||||
    mavenCentral()
 | 
			
		||||
    gradlePluginPortal()
 | 
			
		||||
 | 
			
		||||
    maven("https://maven.neoforged.net/releases") {
 | 
			
		||||
        name = "NeoForge"
 | 
			
		||||
    maven("https://maven.minecraftforge.net") {
 | 
			
		||||
        name = "Forge"
 | 
			
		||||
        content {
 | 
			
		||||
            includeGroup("net.minecraftforge")
 | 
			
		||||
            includeGroup("net.neoforged")
 | 
			
		||||
            includeGroup("net.neoforged.gradle")
 | 
			
		||||
            includeModule("codechicken", "DiffPatch")
 | 
			
		||||
            includeModule("net.covers1624", "Quack")
 | 
			
		||||
            includeGroup("net.minecraftforge.gradle")
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    maven("https://maven.parchmentmc.org") {
 | 
			
		||||
        name = "Librarian"
 | 
			
		||||
        content {
 | 
			
		||||
            includeGroupByRegex("^org\\.parchmentmc.*")
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -32,7 +36,7 @@ repositories {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    maven("https://squiddev.cc/maven") {
 | 
			
		||||
    maven("https://maven.squiddev.cc") {
 | 
			
		||||
        name = "SquidDev"
 | 
			
		||||
        content {
 | 
			
		||||
            includeGroup("cc.tweaked.vanilla-extract")
 | 
			
		||||
@@ -47,9 +51,10 @@ dependencies {
 | 
			
		||||
 | 
			
		||||
    implementation(libs.curseForgeGradle)
 | 
			
		||||
    implementation(libs.fabric.loom)
 | 
			
		||||
    implementation(libs.forgeGradle)
 | 
			
		||||
    implementation(libs.ideaExt)
 | 
			
		||||
    implementation(libs.librarian)
 | 
			
		||||
    implementation(libs.minotaur)
 | 
			
		||||
    implementation(libs.neoGradle.userdev)
 | 
			
		||||
    implementation(libs.vanillaExtract)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -10,8 +10,10 @@ import cc.tweaked.gradle.IdeaRunConfigurations
 | 
			
		||||
import cc.tweaked.gradle.MinecraftConfigurations
 | 
			
		||||
 | 
			
		||||
plugins {
 | 
			
		||||
    id("net.minecraftforge.gradle")
 | 
			
		||||
    // We must apply java-convention after Forge, as we need the fg extension to be present.
 | 
			
		||||
    id("cc-tweaked.java-convention")
 | 
			
		||||
    id("net.neoforged.gradle.userdev")
 | 
			
		||||
    id("org.parchmentmc.librarian.forgegradle")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
plugins.apply(CCTweakedPlugin::class.java)
 | 
			
		||||
@@ -19,20 +21,10 @@ plugins.apply(CCTweakedPlugin::class.java)
 | 
			
		||||
val mcVersion: String by extra
 | 
			
		||||
 | 
			
		||||
minecraft {
 | 
			
		||||
    modIdentifier("computercraft")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
subsystems {
 | 
			
		||||
    parchment {
 | 
			
		||||
    val libs = project.extensions.getByType<VersionCatalogsExtension>().named("libs")
 | 
			
		||||
        minecraftVersion = libs.findVersion("parchmentMc").get().toString()
 | 
			
		||||
        mappingsVersion = libs.findVersion("parchment").get().toString()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
    mappings("parchment", "${libs.findVersion("parchmentMc").get()}-${libs.findVersion("parchment").get()}-$mcVersion")
 | 
			
		||||
 | 
			
		||||
dependencies {
 | 
			
		||||
    val libs = project.extensions.getByType<VersionCatalogsExtension>().named("libs")
 | 
			
		||||
    implementation("net.neoforged:neoforge:${libs.findVersion("neoForge").get()}")
 | 
			
		||||
    accessTransformer(project(":forge").file("src/main/resources/META-INF/accesstransformer.cfg"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
MinecraftConfigurations.setup(project)
 | 
			
		||||
@@ -40,3 +32,13 @@ MinecraftConfigurations.setup(project)
 | 
			
		||||
extensions.configure(CCTweakedExtension::class.java) {
 | 
			
		||||
    linters(minecraft = true, loader = "forge")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
dependencies {
 | 
			
		||||
    val libs = project.extensions.getByType<VersionCatalogsExtension>().named("libs")
 | 
			
		||||
    "minecraft"("net.minecraftforge:forge:$mcVersion-${libs.findVersion("forge").get()}")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
tasks.configureEach {
 | 
			
		||||
    // genIntellijRuns isn't registered until much later, so we need this silly hijinks.
 | 
			
		||||
    if (name == "genIntellijRuns") doLast { IdeaRunConfigurations(project).patch() }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -38,15 +38,23 @@ java {
 | 
			
		||||
repositories {
 | 
			
		||||
    mavenCentral()
 | 
			
		||||
 | 
			
		||||
    val mainMaven = maven("https://squiddev.cc/maven") {
 | 
			
		||||
    val mainMaven = maven("https://maven.squiddev.cc/mirror") {
 | 
			
		||||
        name = "SquidDev"
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    exclusiveContent {
 | 
			
		||||
        forRepositories(mainMaven)
 | 
			
		||||
 | 
			
		||||
        // Include the ForgeGradle repository if present. This requires that ForgeGradle is already present, which we
 | 
			
		||||
        // enforce in our Forge overlay.
 | 
			
		||||
        val fg =
 | 
			
		||||
            project.extensions.findByType(net.minecraftforge.gradle.userdev.DependencyManagementExtension::class.java)
 | 
			
		||||
        if (fg != null) forRepositories(fg.repository)
 | 
			
		||||
 | 
			
		||||
        filter {
 | 
			
		||||
            includeGroup("cc.tweaked")
 | 
			
		||||
            // Things we mirror
 | 
			
		||||
            includeGroup("com.simibubi.create")
 | 
			
		||||
            includeGroup("commoble.morered")
 | 
			
		||||
            includeGroup("dev.architectury")
 | 
			
		||||
            includeGroup("dev.emi")
 | 
			
		||||
@@ -87,9 +95,8 @@ sourceSets.all {
 | 
			
		||||
            check("InlineMeSuggester", CheckSeverity.OFF) // Minecraft uses @Deprecated liberally
 | 
			
		||||
            // Too many false positives right now. Maybe we need an indirection for it later on.
 | 
			
		||||
            check("ReferenceEquality", CheckSeverity.OFF)
 | 
			
		||||
            check("UnusedVariable", CheckSeverity.OFF) // Too many false positives with records.
 | 
			
		||||
            check("EnumOrdinal", CheckSeverity.OFF) // For now. We could replace most of these with EnumMap.
 | 
			
		||||
            check("OperatorPrecedence", CheckSeverity.OFF) // For now.
 | 
			
		||||
            check("AlreadyChecked", CheckSeverity.OFF) // Seems to be broken?
 | 
			
		||||
            check("NonOverridingEquals", CheckSeverity.OFF) // Peripheral.equals makes this hard to avoid
 | 
			
		||||
            check("FutureReturnValueIgnored", CheckSeverity.OFF) // Too many false positives with Netty
 | 
			
		||||
 | 
			
		||||
@@ -127,8 +134,8 @@ tasks.processResources {
 | 
			
		||||
tasks.withType(AbstractArchiveTask::class.java).configureEach {
 | 
			
		||||
    isPreserveFileTimestamps = false
 | 
			
		||||
    isReproducibleFileOrder = true
 | 
			
		||||
    dirMode = Integer.valueOf("755", 8)
 | 
			
		||||
    fileMode = Integer.valueOf("664", 8)
 | 
			
		||||
    filePermissions {}
 | 
			
		||||
    dirPermissions {}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
tasks.jar {
 | 
			
		||||
 
 | 
			
		||||
@@ -38,7 +38,7 @@ publishing {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    repositories {
 | 
			
		||||
        maven("https://squiddev.cc/maven") {
 | 
			
		||||
        maven("https://maven.squiddev.cc") {
 | 
			
		||||
            name = "SquidDev"
 | 
			
		||||
 | 
			
		||||
            credentials(PasswordCredentials::class)
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,6 @@ import org.gradle.api.tasks.SourceSet
 | 
			
		||||
import org.gradle.api.tasks.bundling.Jar
 | 
			
		||||
import org.gradle.api.tasks.compile.JavaCompile
 | 
			
		||||
import org.gradle.api.tasks.javadoc.Javadoc
 | 
			
		||||
import org.gradle.configurationcache.extensions.capitalized
 | 
			
		||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
 | 
			
		||||
import org.gradle.language.jvm.tasks.ProcessResources
 | 
			
		||||
import org.gradle.process.JavaForkOptions
 | 
			
		||||
@@ -35,7 +34,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
 | 
			
		||||
import java.io.File
 | 
			
		||||
import java.io.IOException
 | 
			
		||||
import java.net.URI
 | 
			
		||||
import java.net.URL
 | 
			
		||||
import java.util.regex.Pattern
 | 
			
		||||
 | 
			
		||||
abstract class CCTweakedExtension(
 | 
			
		||||
@@ -182,7 +180,7 @@ abstract class CCTweakedExtension(
 | 
			
		||||
 | 
			
		||||
    fun <T> jacoco(task: NamedDomainObjectProvider<T>) where T : Task, T : JavaForkOptions {
 | 
			
		||||
        val classDump = project.layout.buildDirectory.dir("jacocoClassDump/${task.name}")
 | 
			
		||||
        val reportTaskName = "jacoco${task.name.capitalized()}Report"
 | 
			
		||||
        val reportTaskName = "jacoco${task.name.capitalise()}Report"
 | 
			
		||||
 | 
			
		||||
        val jacoco = project.extensions.getByType(JacocoPluginExtension::class.java)
 | 
			
		||||
        task.configure {
 | 
			
		||||
@@ -226,12 +224,12 @@ abstract class CCTweakedExtension(
 | 
			
		||||
     * where possible.
 | 
			
		||||
     */
 | 
			
		||||
    fun downloadFile(label: String, url: String): File {
 | 
			
		||||
        val url = URL(url)
 | 
			
		||||
        val path = File(url.path)
 | 
			
		||||
        val uri = URI(url)
 | 
			
		||||
        val path = File(uri.path)
 | 
			
		||||
 | 
			
		||||
        project.repositories.ivy {
 | 
			
		||||
            name = label
 | 
			
		||||
            setUrl(URI(url.protocol, url.userInfo, url.host, url.port, path.parent, null, null))
 | 
			
		||||
            setUrl(URI(uri.scheme, uri.userInfo, uri.host, uri.port, path.parent, null, null))
 | 
			
		||||
            patternLayout {
 | 
			
		||||
                artifact("[artifact].[ext]")
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -143,7 +143,7 @@ fun getNextVersion(version: String): String {
 | 
			
		||||
    val lastIndex = mainVersion.lastIndexOf('.')
 | 
			
		||||
    if (lastIndex < 0) throw IllegalArgumentException("Cannot parse version format \"$version\"")
 | 
			
		||||
    val lastVersion = try {
 | 
			
		||||
        version.substring(lastIndex + 1).toInt()
 | 
			
		||||
        mainVersion.substring(lastIndex + 1).toInt()
 | 
			
		||||
    } catch (e: NumberFormatException) {
 | 
			
		||||
        throw IllegalArgumentException("Cannot parse version format \"$version\"", e)
 | 
			
		||||
    }
 | 
			
		||||
@@ -155,3 +155,15 @@ fun getNextVersion(version: String): String {
 | 
			
		||||
    if (dashIndex >= 0) out.append(version, dashIndex, version.length)
 | 
			
		||||
    return out.toString()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Capitalise the first letter of the string.
 | 
			
		||||
 *
 | 
			
		||||
 * This is a replacement for the now deprecated [String.capitalize].
 | 
			
		||||
 */
 | 
			
		||||
fun String.capitalise(): String {
 | 
			
		||||
    if (isEmpty()) return this
 | 
			
		||||
    val first = this[0]
 | 
			
		||||
    val firstTitle = first.titlecaseChar()
 | 
			
		||||
    return if (first == firstTitle) this else firstTitle + substring(1)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,59 +4,23 @@
 | 
			
		||||
 | 
			
		||||
package cc.tweaked.gradle
 | 
			
		||||
 | 
			
		||||
import net.neoforged.gradle.common.runs.run.RunImpl
 | 
			
		||||
import net.neoforged.gradle.common.runs.tasks.RunExec
 | 
			
		||||
import net.neoforged.gradle.dsl.common.extensions.RunnableSourceSet
 | 
			
		||||
import net.neoforged.gradle.dsl.common.runs.run.Run
 | 
			
		||||
import net.minecraftforge.gradle.common.util.RunConfig
 | 
			
		||||
import net.minecraftforge.gradle.common.util.runs.setRunConfigInternal
 | 
			
		||||
import org.gradle.api.plugins.JavaPluginExtension
 | 
			
		||||
import org.gradle.api.tasks.JavaExec
 | 
			
		||||
import org.gradle.api.tasks.SourceSet
 | 
			
		||||
import org.gradle.jvm.toolchain.JavaToolchainService
 | 
			
		||||
import org.gradle.kotlin.dsl.assign
 | 
			
		||||
import org.gradle.kotlin.dsl.create
 | 
			
		||||
import org.gradle.kotlin.dsl.findByType
 | 
			
		||||
import java.nio.file.Files
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Set [JavaExec] task to run a given [RunConfig].
 | 
			
		||||
 *
 | 
			
		||||
 * See also [RunExec].
 | 
			
		||||
 */
 | 
			
		||||
fun JavaExec.setRunConfig(config: Run) {
 | 
			
		||||
    mainClass.set(config.mainClass)
 | 
			
		||||
    workingDir = config.workingDirectory.get().asFile
 | 
			
		||||
    argumentProviders.add { config.programArguments.get() }
 | 
			
		||||
    jvmArgumentProviders.add { config.jvmArguments.get() }
 | 
			
		||||
 | 
			
		||||
    environment(config.environmentVariables.get())
 | 
			
		||||
    systemProperties(config.systemProperties.get())
 | 
			
		||||
 | 
			
		||||
    config.modSources.get().forEach { classpath(it.runtimeClasspath) }
 | 
			
		||||
    classpath(config.classpath)
 | 
			
		||||
    classpath(config.dependencies.get().configuration)
 | 
			
		||||
 | 
			
		||||
    (config as RunImpl).taskDependencies.forEach { dependsOn(it) }
 | 
			
		||||
fun JavaExec.setRunConfig(config: RunConfig) {
 | 
			
		||||
    dependsOn("prepareRuns")
 | 
			
		||||
    setRunConfigInternal(project, this, config)
 | 
			
		||||
    doFirst("Create working directory") { Files.createDirectories(workingDir.toPath()) }
 | 
			
		||||
 | 
			
		||||
    javaLauncher.set(
 | 
			
		||||
        project.extensions.getByType(JavaToolchainService::class.java)
 | 
			
		||||
            .launcherFor(project.extensions.getByType(JavaPluginExtension::class.java).toolchain),
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    doFirst("Create working directory") { Files.createDirectories(workingDir.toPath()) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Add a new [Run.modSource] with a specific mod id.
 | 
			
		||||
 */
 | 
			
		||||
fun Run.modSourceAs(sourceSet: SourceSet, mod: String) {
 | 
			
		||||
    // NeoGradle requires a RunnableSourceSet to be present, so we inject it into other project's source sets.
 | 
			
		||||
    val runnable = sourceSet.extensions.findByType<RunnableSourceSet>() ?: run {
 | 
			
		||||
        val extension = sourceSet.extensions.create<RunnableSourceSet>(RunnableSourceSet.NAME, project)
 | 
			
		||||
        extension.modIdentifier = mod
 | 
			
		||||
        extension.modIdentifier.finalizeValueOnRead()
 | 
			
		||||
        extension
 | 
			
		||||
    }
 | 
			
		||||
    if (runnable.modIdentifier.get() != mod) throw IllegalArgumentException("Multiple mod identifiers")
 | 
			
		||||
 | 
			
		||||
    modSource(sourceSet)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										120
									
								
								buildSrc/src/main/kotlin/cc/tweaked/gradle/MergeTrees.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										120
									
								
								buildSrc/src/main/kotlin/cc/tweaked/gradle/MergeTrees.kt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,120 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2024 The CC: Tweaked Developers
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
package cc.tweaked.gradle
 | 
			
		||||
 | 
			
		||||
import cc.tweaked.vanillaextract.core.util.MoreFiles
 | 
			
		||||
import org.gradle.api.Action
 | 
			
		||||
import org.gradle.api.DefaultTask
 | 
			
		||||
import org.gradle.api.GradleException
 | 
			
		||||
import org.gradle.api.file.*
 | 
			
		||||
import org.gradle.api.model.ObjectFactory
 | 
			
		||||
import org.gradle.api.provider.ListProperty
 | 
			
		||||
import org.gradle.api.tasks.*
 | 
			
		||||
import javax.inject.Inject
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Merge common files across multiple directories into one destination directory.
 | 
			
		||||
 *
 | 
			
		||||
 * This is intended for merging the generated resources from the Forge and Fabric projects. Files common between the two
 | 
			
		||||
 * are written to the global [output] directory, while distinct files are written to the per-source
 | 
			
		||||
 * [MergeTrees.Source.output] directory.
 | 
			
		||||
 */
 | 
			
		||||
abstract class MergeTrees : DefaultTask() {
 | 
			
		||||
    /**
 | 
			
		||||
     * A source directory to read from.
 | 
			
		||||
     */
 | 
			
		||||
    interface Source {
 | 
			
		||||
        /**
 | 
			
		||||
         * The folder contianing all input files.
 | 
			
		||||
         */
 | 
			
		||||
        @get:InputFiles
 | 
			
		||||
        @get:PathSensitive(PathSensitivity.RELATIVE)
 | 
			
		||||
        val input: ConfigurableFileTree
 | 
			
		||||
 | 
			
		||||
        fun input(configure: Action<ConfigurableFileTree>) {
 | 
			
		||||
            configure.execute(input)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * The folder to write files unique to this folder to.
 | 
			
		||||
         */
 | 
			
		||||
        @get:OutputDirectory
 | 
			
		||||
        val output: DirectoryProperty
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The list of sources.
 | 
			
		||||
     */
 | 
			
		||||
    @get:Nested
 | 
			
		||||
    abstract val sources: ListProperty<Source>
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Add and configure a new source.
 | 
			
		||||
     */
 | 
			
		||||
    fun source(configure: Action<Source>) {
 | 
			
		||||
        val instance = objectFactory.newInstance(Source::class.java)
 | 
			
		||||
        configure.execute(instance)
 | 
			
		||||
        instance.output.disallowChanges()
 | 
			
		||||
        sources.add(instance)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The directory to write common files to.
 | 
			
		||||
     */
 | 
			
		||||
    @get:OutputDirectory
 | 
			
		||||
    abstract val output: DirectoryProperty
 | 
			
		||||
 | 
			
		||||
    @get:Inject
 | 
			
		||||
    protected abstract val objectFactory: ObjectFactory
 | 
			
		||||
 | 
			
		||||
    @get:Inject
 | 
			
		||||
    protected abstract val fsOperations: FileSystemOperations
 | 
			
		||||
 | 
			
		||||
    @TaskAction
 | 
			
		||||
    fun run() {
 | 
			
		||||
        val sources = this.sources.get()
 | 
			
		||||
        if (sources.isEmpty()) throw GradleException("Cannot have an empty list of sources")
 | 
			
		||||
 | 
			
		||||
        val files = mutableMapOf<String, SharedFile>()
 | 
			
		||||
        for (source in sources) {
 | 
			
		||||
            source.input.visit(
 | 
			
		||||
                object : FileVisitor {
 | 
			
		||||
                    override fun visitDir(dirDetails: FileVisitDetails) = Unit
 | 
			
		||||
                    override fun visitFile(fileDetails: FileVisitDetails) {
 | 
			
		||||
                        val path = fileDetails.file.toRelativeString(source.input.dir)
 | 
			
		||||
                        val hash = MoreFiles.computeSha1(fileDetails.file.toPath())
 | 
			
		||||
 | 
			
		||||
                        val existing = files[path]
 | 
			
		||||
                        if (existing == null) {
 | 
			
		||||
                            files[path] = SharedFile(hash, 1)
 | 
			
		||||
                        } else if (existing.hash == hash) {
 | 
			
		||||
                            existing.found++
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                },
 | 
			
		||||
            )
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        val sharedFiles = files.entries.asSequence().filter { (_, v) -> v.found == sources.size }.map { (k, _) -> k }.toList()
 | 
			
		||||
 | 
			
		||||
        // Copy shared files to the common directory
 | 
			
		||||
        fsOperations.sync {
 | 
			
		||||
            from(sources[0].input)
 | 
			
		||||
            into(output)
 | 
			
		||||
            include(sharedFiles)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // And all other files to their per-source directory
 | 
			
		||||
        for (source in sources) {
 | 
			
		||||
            fsOperations.sync {
 | 
			
		||||
                from(source.input)
 | 
			
		||||
                into(source.output)
 | 
			
		||||
                exclude(sharedFiles)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    class SharedFile(val hash: String, var found: Int)
 | 
			
		||||
}
 | 
			
		||||
@@ -4,6 +4,7 @@
 | 
			
		||||
 | 
			
		||||
package cc.tweaked.gradle
 | 
			
		||||
 | 
			
		||||
import net.minecraftforge.gradle.common.util.RunConfig
 | 
			
		||||
import org.gradle.api.GradleException
 | 
			
		||||
import org.gradle.api.file.FileSystemOperations
 | 
			
		||||
import org.gradle.api.invocation.Gradle
 | 
			
		||||
@@ -64,6 +65,14 @@ abstract class ClientJavaExec : JavaExec() {
 | 
			
		||||
        setTestProperties()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Set this task to run a given [RunConfig].
 | 
			
		||||
     */
 | 
			
		||||
    fun setRunConfig(config: RunConfig) {
 | 
			
		||||
        (this as JavaExec).setRunConfig(config)
 | 
			
		||||
        setTestProperties() // setRunConfig may clobber some properties, ensure everything is set.
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Copy configuration from a task with the given name.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -46,7 +46,7 @@ abstract class NpmInstall : DefaultTask() {
 | 
			
		||||
    @TaskAction
 | 
			
		||||
    fun install() {
 | 
			
		||||
        project.exec {
 | 
			
		||||
            commandLine("npm", "ci")
 | 
			
		||||
            commandLine(ProcessHelpers.getExecutable("npm"), "ci")
 | 
			
		||||
            workingDir = projectRoot.get().asFile
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -59,6 +59,6 @@ abstract class NpmInstall : DefaultTask() {
 | 
			
		||||
abstract class NpxExecToDir : ExecToDir() {
 | 
			
		||||
    init {
 | 
			
		||||
        dependsOn(NpmInstall.TASK_NAME)
 | 
			
		||||
        executable = "npx"
 | 
			
		||||
        executable = ProcessHelpers.getExecutable("npx")
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ import org.gradle.api.GradleException
 | 
			
		||||
import java.io.BufferedReader
 | 
			
		||||
import java.io.File
 | 
			
		||||
import java.io.InputStreamReader
 | 
			
		||||
import java.nio.charset.StandardCharsets
 | 
			
		||||
 | 
			
		||||
internal object ProcessHelpers {
 | 
			
		||||
    fun startProcess(vararg command: String): Process {
 | 
			
		||||
@@ -34,7 +35,7 @@ internal object ProcessHelpers {
 | 
			
		||||
        val process = startProcess(*command)
 | 
			
		||||
        process.outputStream.close()
 | 
			
		||||
 | 
			
		||||
        val out = BufferedReader(InputStreamReader(process.inputStream)).use { reader ->
 | 
			
		||||
        val out = BufferedReader(InputStreamReader(process.inputStream, StandardCharsets.UTF_8)).use { reader ->
 | 
			
		||||
            reader.lines().filter { it.isNotEmpty() }.toList()
 | 
			
		||||
        }
 | 
			
		||||
        ProcessGroovyMethods.closeStreams(process)
 | 
			
		||||
@@ -46,6 +47,28 @@ internal object ProcessHelpers {
 | 
			
		||||
        val path = System.getenv("PATH") ?: return false
 | 
			
		||||
        return path.splitToSequence(File.pathSeparator).any { File(it, name).exists() }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Search for an executable on the `PATH` if required.
 | 
			
		||||
     *
 | 
			
		||||
     * [Process]/[ProcessBuilder] does not handle all executable file extensions on Windows (such as `.com). When on
 | 
			
		||||
     * Windows, this function searches `PATH` and `PATHEXT` for an executable matching [name].
 | 
			
		||||
     */
 | 
			
		||||
    fun getExecutable(name: String): String {
 | 
			
		||||
        if (!System.getProperty("os.name").lowercase().contains("windows")) return name
 | 
			
		||||
 | 
			
		||||
        val path = (System.getenv("PATH") ?: return name).split(File.pathSeparator)
 | 
			
		||||
        val pathExt = (System.getenv("PATHEXT") ?: return name).split(File.pathSeparator)
 | 
			
		||||
 | 
			
		||||
        for (pathEntry in path) {
 | 
			
		||||
            for (ext in pathExt) {
 | 
			
		||||
                val resolved = File(pathEntry, name + ext)
 | 
			
		||||
                if (resolved.exists()) return resolved.getAbsolutePath()
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return name
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
internal fun Process.waitForOrThrow(message: String) {
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,51 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2023 The CC: Tweaked Developers
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
package net.minecraftforge.gradle.common.util.runs
 | 
			
		||||
 | 
			
		||||
import net.minecraftforge.gradle.common.util.RunConfig
 | 
			
		||||
import org.gradle.api.Project
 | 
			
		||||
import org.gradle.process.CommandLineArgumentProvider
 | 
			
		||||
import org.gradle.process.JavaExecSpec
 | 
			
		||||
import java.io.File
 | 
			
		||||
import java.util.function.Supplier
 | 
			
		||||
import java.util.stream.Collectors
 | 
			
		||||
import java.util.stream.Stream
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Set up a [JavaExecSpec] to execute a [RunConfig].
 | 
			
		||||
 *
 | 
			
		||||
 * [MinecraftRunTask] sets up all its properties when the task is executed, rather than when configured. As such, it's
 | 
			
		||||
 * not possible to use [cc.tweaked.gradle.copyToFull] like we do for Fabric. Instead, we set up the task manually.
 | 
			
		||||
 *
 | 
			
		||||
 * Unfortunately most of the functionality we need is package-private, and so we have to put our code into the package.
 | 
			
		||||
 */
 | 
			
		||||
internal fun setRunConfigInternal(project: Project, spec: JavaExecSpec, config: RunConfig) {
 | 
			
		||||
    spec.workingDir = File(config.workingDirectory)
 | 
			
		||||
 | 
			
		||||
    spec.mainClass.set(config.main)
 | 
			
		||||
    for (source in config.allSources) spec.classpath(source.runtimeClasspath)
 | 
			
		||||
 | 
			
		||||
    val originalTask = project.tasks.named(config.taskName, MinecraftRunTask::class.java)
 | 
			
		||||
 | 
			
		||||
    // Add argument and JVM argument via providers, to be as lazy as possible with fetching artifacts.
 | 
			
		||||
    val lazyTokens = RunConfigGenerator.configureTokensLazy(
 | 
			
		||||
        project, config, RunConfigGenerator.mapModClassesToGradle(project, config),
 | 
			
		||||
        originalTask.get().minecraftArtifacts,
 | 
			
		||||
        originalTask.get().runtimeClasspathArtifacts,
 | 
			
		||||
    )
 | 
			
		||||
    spec.argumentProviders.add(
 | 
			
		||||
        CommandLineArgumentProvider {
 | 
			
		||||
            RunConfigGenerator.getArgsStream(config, lazyTokens, false).toList()
 | 
			
		||||
        },
 | 
			
		||||
    )
 | 
			
		||||
    spec.jvmArgumentProviders.add(
 | 
			
		||||
        CommandLineArgumentProvider {
 | 
			
		||||
            (if (config.isClient) config.jvmArgs + originalTask.get().additionalClientArgs.get() else config.jvmArgs).map { config.replace(lazyTokens, it) } +
 | 
			
		||||
                config.properties.map { (k, v) -> "-D${k}=${config.replace(lazyTokens, v)}" }
 | 
			
		||||
        },
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    for ((key, value) in config.environment) spec.environment(key, config.replace(lazyTokens, value))
 | 
			
		||||
}
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
# SPDX-FileCopyrightText: 2021 The CC: Tweaked Developers
 | 
			
		||||
#
 | 
			
		||||
# SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
FROM gitpod/workspace-base
 | 
			
		||||
 | 
			
		||||
USER gitpod
 | 
			
		||||
 | 
			
		||||
RUN sudo apt-get -q update \
 | 
			
		||||
 && sudo apt-get install -yq openjdk-16-jdk python3-pip npm \
 | 
			
		||||
 && sudo pip3 install pre-commit \
 | 
			
		||||
 && sudo update-java-alternatives --set java-1.16.0-openjdk-amd64
 | 
			
		||||
@@ -131,7 +131,7 @@ different.
 | 
			
		||||
First, we require the dfpwm module and call [`cc.audio.dfpwm.make_decoder`] to construct a new decoder. This decoder
 | 
			
		||||
accepts blocks of DFPWM data and converts it to a list of 8-bit amplitudes, which we can then play with our speaker.
 | 
			
		||||
 | 
			
		||||
As mentioned above, [`speaker.playAudio`] accepts at most 128×1024 samples in one go. DFPMW uses a single bit for each
 | 
			
		||||
As mentioned above, [`speaker.playAudio`] accepts at most 128×1024 samples in one go. DFPWM uses a single bit for each
 | 
			
		||||
sample, which means we want to process our audio in chunks of 16×1024 bytes (16KiB). In order to do this, we use
 | 
			
		||||
[`io.lines`], which provides a nice way to loop over chunks of a file. You can of course just use [`fs.open`] and
 | 
			
		||||
[`fs.ReadHandle.read`] if you prefer.
 | 
			
		||||
@@ -191,7 +191,7 @@ end
 | 
			
		||||
 | 
			
		||||
> [Confused?][!NOTE]
 | 
			
		||||
> Don't worry if you don't understand this example. It's quite advanced, and does use some ideas that this guide doesn't
 | 
			
		||||
> cover. That said, don't be afraid to ask on [GitHub Discussions] or [IRC] either!
 | 
			
		||||
> cover. That said, don't be afraid to ask [the community for help][community].
 | 
			
		||||
 | 
			
		||||
It's worth noting that the examples of audio processing we've mentioned here are about manipulating the _amplitude_ of
 | 
			
		||||
the wave. If you wanted to modify the _frequency_ (for instance, shifting the pitch), things get rather more complex.
 | 
			
		||||
@@ -205,5 +205,4 @@ This is, I'm afraid, left as an exercise to the reader.
 | 
			
		||||
[PCM]: https://en.wikipedia.org/wiki/Pulse-code_modulation "Pulse-code Modulation - Wikipedia"
 | 
			
		||||
[Ring Buffer]: https://en.wikipedia.org/wiki/Circular_buffer "Circular buffer - Wikipedia"
 | 
			
		||||
[Sine Wave]: https://en.wikipedia.org/wiki/Sine_wave "Sine wave - Wikipedia"
 | 
			
		||||
[GitHub Discussions]: https://github.com/cc-tweaked/CC-Tweaked/discussions
 | 
			
		||||
[IRC]: https://webchat.esper.net/?channels=computercraft "#computercraft on EsperNet"
 | 
			
		||||
[Community]: /#community
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										20
									
								
								doc/index.md
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								doc/index.md
									
									
									
									
									
								
							@@ -4,7 +4,14 @@ SPDX-FileCopyrightText: 2020 The CC: Tweaked Developers
 | 
			
		||||
SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
# 
 | 
			
		||||
<h1>
 | 
			
		||||
    <picture>
 | 
			
		||||
        <source media="(prefers-color-scheme: dark)" srcset="logo-darkmode.png">
 | 
			
		||||
        <source media="(prefers-color-scheme: light)" srcset="logo.png">
 | 
			
		||||
        <img alt="CC: Tweaked" src="logo.png">
 | 
			
		||||
    </picture>
 | 
			
		||||
</h1>
 | 
			
		||||
 | 
			
		||||
CC: Tweaked is a mod for Minecraft which adds programmable computers, turtles and more to the game. A fork of the
 | 
			
		||||
much-beloved [ComputerCraft], it continues its legacy with improved performance and stability, along with a wealth of
 | 
			
		||||
new features.
 | 
			
		||||
@@ -38,12 +45,16 @@ little daunting getting started. Thankfully, there's several fantastic tutorials
 | 
			
		||||
 | 
			
		||||
 - [Direwolf20's ComputerCraft tutorials](https://www.youtube.com/watch?v=wrUHUhfCY5A "ComputerCraft Tutorial Episode 1 - HELP! and Hello World")
 | 
			
		||||
 - [Sethbling's ComputerCraft series](https://www.youtube.com/watch?v=DSsx4VSe-Uk "Programming Tutorial with Minecraft Turtles -- Ep. 1: Intro to Turtles and If-Then-Else_End")
 | 
			
		||||
 - [Lyqyd's Computer Basics 1](http://www.computercraft.info/forums2/index.php?/topic/15033-computer-basics-i/ "Computer Basics I")
 | 
			
		||||
 - [Lyqyd's Computer Basics 1](https://ccf.squiddev.cc/forums2/index.php?/topic/15033-computer-basics-i/ "Computer Basics I")
 | 
			
		||||
 | 
			
		||||
Once you're a little more familiar with the mod, the sidebar and links below provide more detailed documentation on the
 | 
			
		||||
various APIs and peripherals provided by the mod.
 | 
			
		||||
 | 
			
		||||
If you get stuck, do [ask a question on GitHub][GitHub Discussions] or pop in to the ComputerCraft's [IRC channel][IRC].
 | 
			
		||||
<h2 id="community">Community</h2>
 | 
			
		||||
If you need help getting started with CC: Tweaked, want to show off your latest project, or just want to chat about
 | 
			
		||||
ComputerCraft, do check out our [GitHub discussions page][GitHub discussions]! There's also a fairly populated,
 | 
			
		||||
albeit quiet IRC channel on [EsperNet], if that's more your cup of tea. You can join `#computercraft` through your
 | 
			
		||||
desktop client, or online using [KiwiIRC].
 | 
			
		||||
 | 
			
		||||
## Get Involved
 | 
			
		||||
CC: Tweaked lives on [GitHub]. If you've got any ideas, feedback or bugs please do [create an issue][bug].
 | 
			
		||||
@@ -58,4 +69,5 @@ CC: Tweaked lives on [GitHub]. If you've got any ideas, feedback or bugs please
 | 
			
		||||
[Fabric]: https://fabricmc.net/use/installer/ "Download Fabric."
 | 
			
		||||
[lua]: https://www.lua.org/ "Lua's main website"
 | 
			
		||||
[GitHub Discussions]: https://github.com/cc-tweaked/CC-Tweaked/discussions
 | 
			
		||||
[IRC]: https://webchat.esper.net/?channels=computercraft "#computercraft on EsperNet"
 | 
			
		||||
[EsperNet]: https://www.esper.net/
 | 
			
		||||
[KiwiIRC]: https://kiwiirc.com/nextclient/#irc://irc.esper.net:+6697/#computercraft "#computercraft on EsperNet"
 | 
			
		||||
 
 | 
			
		||||
@@ -45,12 +45,16 @@ little daunting getting started. Thankfully, there's several fantastic tutorials
 | 
			
		||||
 | 
			
		||||
 - [Direwolf20's ComputerCraft tutorials](https://www.youtube.com/watch?v=wrUHUhfCY5A "ComputerCraft Tutorial Episode 1 - HELP! and Hello World")
 | 
			
		||||
 - [Sethbling's ComputerCraft series](https://www.youtube.com/watch?v=DSsx4VSe-Uk "Programming Tutorial with Minecraft Turtles -- Ep. 1: Intro to Turtles and If-Then-Else_End")
 | 
			
		||||
 - [Lyqyd's Computer Basics 1](http://www.computercraft.info/forums2/index.php?/topic/15033-computer-basics-i/ "Computer Basics I")
 | 
			
		||||
 - [Lyqyd's Computer Basics 1](https://ccf.squiddev.cc/forums2/index.php?/topic/15033-computer-basics-i/ "Computer Basics I")
 | 
			
		||||
 | 
			
		||||
Once you're a little more familiar with the mod, the [wiki](https://tweaked.cc/) provides more detailed documentation on the
 | 
			
		||||
various APIs and peripherals provided by the mod.
 | 
			
		||||
 | 
			
		||||
If you get stuck, do [ask a question on GitHub][GitHub Discussions] or pop in to the ComputerCraft's [IRC channel][IRC].
 | 
			
		||||
## Community
 | 
			
		||||
If you need help getting started with CC: Tweaked, want to show off your latest project, or just want to chat about
 | 
			
		||||
ComputerCraft, do check out our [GitHub discussions page][GitHub discussions]! There's also a fairly populated,
 | 
			
		||||
albeit quiet IRC channel on [EsperNet], if that's more your cup of tea. You can join `#computercraft` through your
 | 
			
		||||
desktop client, or online using [KiwiIRC].
 | 
			
		||||
 | 
			
		||||
## Get Involved
 | 
			
		||||
CC: Tweaked lives on [GitHub]. If you've got any ideas, feedback or bugs please do [create an issue][bug].
 | 
			
		||||
@@ -60,4 +64,5 @@ CC: Tweaked lives on [GitHub]. If you've got any ideas, feedback or bugs please
 | 
			
		||||
[computercraft]: https://github.com/dan200/ComputerCraft "ComputerCraft on GitHub"
 | 
			
		||||
[lua]: https://www.lua.org/ "Lua's main website"
 | 
			
		||||
[GitHub Discussions]: https://github.com/cc-tweaked/CC-Tweaked/discussions
 | 
			
		||||
[IRC]: http://webchat.esper.net/?channels=computercraft "#computercraft on EsperNet"
 | 
			
		||||
[EsperNet]: https://www.esper.net/
 | 
			
		||||
[KiwiIRC]: https://kiwiirc.com/nextclient/#irc://irc.esper.net:+6697/#computercraft "#computercraft on EsperNet"
 | 
			
		||||
 
 | 
			
		||||
@@ -25,13 +25,13 @@ as documentation for breaking changes and "gotchas" one should look out for betw
 | 
			
		||||
 | 
			
		||||
 - Update to Lua 5.2:
 | 
			
		||||
   - Support for Lua 5.0's pseudo-argument `arg` has been removed. You should always use `...` for varargs.
 | 
			
		||||
   - Environments are no longer baked into the runtime, and instead use the `_ENV` local or upvalue. `getfenv`/`setfenv`
 | 
			
		||||
     now only work on Lua functions with an `_ENV` upvalue. `getfenv` will return the global environment when called
 | 
			
		||||
     with other functions, and `setfenv` will have no effect.
 | 
			
		||||
   - `load`/`loadstring` defaults to using the global environment (`_G`) rather than the current coroutine's
 | 
			
		||||
   - Environments are no longer baked into the runtime, and instead use the `_ENV` local or upvalue. [`getfenv`]/[`setfenv`]
 | 
			
		||||
     now only work on Lua functions with an `_ENV` upvalue. [`getfenv`] will return the global environment when called
 | 
			
		||||
     with other functions, and [`setfenv`] will have no effect.
 | 
			
		||||
   - [`load`]/[`loadstring`] defaults to using the global environment (`_G`) rather than the current coroutine's
 | 
			
		||||
     environment.
 | 
			
		||||
   - Support for dumping functions (`string.dump`) and loading binary chunks has been removed.
 | 
			
		||||
   - `math.random` now uses Lua 5.4's random number generator.
 | 
			
		||||
   - Support for dumping functions ([`string.dump`]) and loading binary chunks has been removed.
 | 
			
		||||
   - [`math.random`] now uses Lua 5.4's random number generator.
 | 
			
		||||
 | 
			
		||||
 - File handles, HTTP requests and websockets now always use the original bytes rather than encoding/decoding to UTF-8.
 | 
			
		||||
 | 
			
		||||
@@ -44,7 +44,7 @@ as documentation for breaking changes and "gotchas" one should look out for betw
 | 
			
		||||
   `keys.enter` constant was queued when the key was pressed)
 | 
			
		||||
 | 
			
		||||
 - Minecraft 1.13 removed the concept of item damage and block metadata (see ["The Flattening"][flattening]). As a
 | 
			
		||||
   result `turtle.inspect` no longer provides block metadata, and `turtle.getItemDetail` no longer provides damage.
 | 
			
		||||
   result [`turtle.inspect`] no longer provides block metadata, and [`turtle.getItemDetail`] no longer provides damage.
 | 
			
		||||
 | 
			
		||||
   - Block states (`turtle.inspect().state`) should provide all the same information as block metadata, but in a much
 | 
			
		||||
     more understandable format.
 | 
			
		||||
@@ -70,12 +70,12 @@ as documentation for breaking changes and "gotchas" one should look out for betw
 | 
			
		||||
 - Unlabelled computers and turtles now keep their ID when broken, meaning that unlabelled computers/items do not stack.
 | 
			
		||||
 | 
			
		||||
## ComputerCraft 1.80pr1 {#cc-1.80}
 | 
			
		||||
 - Programs run via `shell.run` are now started in their own isolated environment. This means globals set by programs
 | 
			
		||||
 - Programs run via [`shell.run`] are now started in their own isolated environment. This means globals set by programs
 | 
			
		||||
   will not be accessible outside of this program.
 | 
			
		||||
 | 
			
		||||
 - Programs containing `/` are looked up in the current directory and are no longer looked up on the path. For instance,
 | 
			
		||||
   you can no longer type `turtle/excavate` to run `/rom/programs/turtle/excavate.lua`.
 | 
			
		||||
 | 
			
		||||
[flattening]: https://minecraft.wiki/w/Java_Edition_1.13/Flattening
 | 
			
		||||
[legal_data_pack]: https://minecraft.gamepedia.com/Tutorials/Creating_a_data_pack#Legal_characters
 | 
			
		||||
[legal_data_pack]: https://minecraft.wiki/w/Tutorials/Creating_a_data_pack#Legal_characters
 | 
			
		||||
[datapack-example]: https://github.com/cc-tweaked/datapack-example "An example datapack for CC: Tweaked"
 | 
			
		||||
 
 | 
			
		||||
@@ -2,15 +2,15 @@
 | 
			
		||||
#
 | 
			
		||||
# SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
org.gradle.jvmargs=-Xmx3G
 | 
			
		||||
org.gradle.jvmargs=-Xmx3G -Dfile.encoding=UTF-8
 | 
			
		||||
org.gradle.parallel=true
 | 
			
		||||
 | 
			
		||||
kotlin.stdlib.default.dependency=false
 | 
			
		||||
kotlin.jvm.target.validation.mode=error
 | 
			
		||||
 | 
			
		||||
# Mod properties
 | 
			
		||||
isUnstable=true
 | 
			
		||||
modVersion=1.110.2
 | 
			
		||||
isUnstable=false
 | 
			
		||||
modVersion=1.113.0
 | 
			
		||||
 | 
			
		||||
# Minecraft properties: We want to configure this here so we can read it in settings.gradle
 | 
			
		||||
mcVersion=1.20.4
 | 
			
		||||
mcVersion=1.20.1
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								gradle/gradle-daemon-jvm.properties
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								gradle/gradle-daemon-jvm.properties
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
#This file is generated by updateDaemonJvm
 | 
			
		||||
toolchainVersion=17
 | 
			
		||||
@@ -7,26 +7,26 @@
 | 
			
		||||
# Minecraft
 | 
			
		||||
# MC version is specified in gradle.properties, as we need that in settings.gradle.
 | 
			
		||||
# Remember to update corresponding versions in fabric.mod.json/mods.toml
 | 
			
		||||
fabric-api = "0.93.1+1.20.4"
 | 
			
		||||
fabric-loader = "0.15.3"
 | 
			
		||||
neoForge = "20.4.210"
 | 
			
		||||
neoForgeSpi = "8.0.1"
 | 
			
		||||
fabric-api = "0.86.1+1.20.1"
 | 
			
		||||
fabric-loader = "0.14.21"
 | 
			
		||||
forge = "47.1.0"
 | 
			
		||||
forgeSpi = "7.0.1"
 | 
			
		||||
mixin = "0.8.5"
 | 
			
		||||
parchment = "2023.12.31"
 | 
			
		||||
parchmentMc = "1.20.3"
 | 
			
		||||
yarn = "1.20.4+build.3"
 | 
			
		||||
parchment = "2023.08.20"
 | 
			
		||||
parchmentMc = "1.20.1"
 | 
			
		||||
yarn = "1.20.1+build.10"
 | 
			
		||||
 | 
			
		||||
# Core dependencies (these versions are tied to the version Minecraft uses)
 | 
			
		||||
fastutil = "8.5.12"
 | 
			
		||||
guava = "32.1.2-jre"
 | 
			
		||||
netty = "4.1.97.Final"
 | 
			
		||||
slf4j = "2.0.7"
 | 
			
		||||
fastutil = "8.5.9"
 | 
			
		||||
guava = "31.1-jre"
 | 
			
		||||
netty = "4.1.82.Final"
 | 
			
		||||
slf4j = "2.0.1"
 | 
			
		||||
 | 
			
		||||
# Core dependencies (independent of Minecraft)
 | 
			
		||||
asm = "9.6"
 | 
			
		||||
autoService = "1.1.1"
 | 
			
		||||
checkerFramework = "3.42.0"
 | 
			
		||||
cobalt = "0.9.2"
 | 
			
		||||
cobalt = "0.9.3"
 | 
			
		||||
commonsCli = "1.6.0"
 | 
			
		||||
jetbrainsAnnotations = "24.1.0"
 | 
			
		||||
jsr305 = "3.0.2"
 | 
			
		||||
@@ -36,16 +36,18 @@ kotlin-coroutines = "1.7.3"
 | 
			
		||||
nightConfig = "3.6.7"
 | 
			
		||||
 | 
			
		||||
# Minecraft mods
 | 
			
		||||
emi = "1.0.30+1.20.4"
 | 
			
		||||
emi = "1.0.8+1.20.1"
 | 
			
		||||
fabricPermissions = "0.3.20230723"
 | 
			
		||||
iris = "1.6.14+1.20.4"
 | 
			
		||||
jei = "17.3.0.48"
 | 
			
		||||
modmenu = "9.0.0"
 | 
			
		||||
iris = "1.6.4+1.20"
 | 
			
		||||
jei = "15.2.0.22"
 | 
			
		||||
modmenu = "7.1.0"
 | 
			
		||||
moreRed = "4.0.0.4"
 | 
			
		||||
oculus = "1.2.5"
 | 
			
		||||
rei = "14.0.688"
 | 
			
		||||
rei = "12.0.626"
 | 
			
		||||
rubidium = "0.6.1"
 | 
			
		||||
sodium = "mc1.20-0.4.10"
 | 
			
		||||
create-forge = "0.5.1.f-33"
 | 
			
		||||
create-fabric = "0.5.1-f-build.1467+mc1.20.1"
 | 
			
		||||
 | 
			
		||||
# Testing
 | 
			
		||||
hamcrest = "2.2"
 | 
			
		||||
@@ -56,22 +58,23 @@ jmh = "1.37"
 | 
			
		||||
# Build tools
 | 
			
		||||
cctJavadoc = "1.8.2"
 | 
			
		||||
checkstyle = "10.14.1"
 | 
			
		||||
curseForgeGradle = "1.1.18"
 | 
			
		||||
errorProne-core = "2.23.0"
 | 
			
		||||
curseForgeGradle = "1.0.14"
 | 
			
		||||
errorProne-core = "2.27.0"
 | 
			
		||||
errorProne-plugin = "3.1.0"
 | 
			
		||||
fabric-loom = "1.5.7"
 | 
			
		||||
fabric-loom = "1.7.1"
 | 
			
		||||
forgeGradle = "6.0.21"
 | 
			
		||||
githubRelease = "2.5.2"
 | 
			
		||||
gradleVersions = "0.50.0"
 | 
			
		||||
ideaExt = "1.1.7"
 | 
			
		||||
illuaminate = "0.1.0-71-g378d86e"
 | 
			
		||||
illuaminate = "0.1.0-73-g43ee16c"
 | 
			
		||||
librarian = "1.+"
 | 
			
		||||
lwjgl = "3.3.3"
 | 
			
		||||
minotaur = "2.8.7"
 | 
			
		||||
neoGradle = "7.0.100"
 | 
			
		||||
minotaur = "2.+"
 | 
			
		||||
nullAway = "0.10.25"
 | 
			
		||||
spotless = "6.23.3"
 | 
			
		||||
taskTree = "2.1.1"
 | 
			
		||||
teavm = "0.10.0-SQUID.3"
 | 
			
		||||
vanillaExtract = "0.1.2"
 | 
			
		||||
teavm = "0.11.0-SQUID.1"
 | 
			
		||||
vanillaExtract = "0.1.3"
 | 
			
		||||
versionCatalogUpdate = "0.8.1"
 | 
			
		||||
 | 
			
		||||
[libraries]
 | 
			
		||||
@@ -83,7 +86,7 @@ checkerFramework = { module = "org.checkerframework:checker-qual", version.ref =
 | 
			
		||||
cobalt = { module = "cc.tweaked:cobalt", version.ref = "cobalt" }
 | 
			
		||||
commonsCli = { module = "commons-cli:commons-cli", version.ref = "commonsCli" }
 | 
			
		||||
fastutil = { module = "it.unimi.dsi:fastutil", version.ref = "fastutil" }
 | 
			
		||||
neoForgeSpi = { module = "net.neoforged:neoforgespi", version.ref = "neoForgeSpi" }
 | 
			
		||||
forgeSpi = { module = "net.minecraftforge:forgespi", version.ref = "forgeSpi" }
 | 
			
		||||
guava = { module = "com.google.guava:guava", version.ref = "guava" }
 | 
			
		||||
jetbrainsAnnotations = { module = "org.jetbrains:annotations", version.ref = "jetbrainsAnnotations" }
 | 
			
		||||
jsr305 = { module = "com.google.code.findbugs:jsr305", version.ref = "jsr305" }
 | 
			
		||||
@@ -99,15 +102,17 @@ nightConfig-toml = { module = "com.electronwill.night-config:toml", version.ref
 | 
			
		||||
slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
 | 
			
		||||
 | 
			
		||||
# Minecraft mods
 | 
			
		||||
fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fabric-api" }
 | 
			
		||||
fabric-loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabric-loader" }
 | 
			
		||||
fabric-junit = { module = "net.fabricmc:fabric-loader-junit", version.ref = "fabric-loader" }
 | 
			
		||||
fabricPermissions = { module = "me.lucko:fabric-permissions-api", version.ref = "fabricPermissions" }
 | 
			
		||||
create-fabric = { module = "com.simibubi.create:create-fabric-1.20.1", version.ref = "create-fabric" }
 | 
			
		||||
create-forge = { module = "com.simibubi.create:create-1.20.1", version.ref = "create-forge" }
 | 
			
		||||
emi = { module = "dev.emi:emi-xplat-mojmap", version.ref = "emi" }
 | 
			
		||||
fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fabric-api" }
 | 
			
		||||
fabric-junit = { module = "net.fabricmc:fabric-loader-junit", version.ref = "fabric-loader" }
 | 
			
		||||
fabric-loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabric-loader" }
 | 
			
		||||
fabricPermissions = { module = "me.lucko:fabric-permissions-api", version.ref = "fabricPermissions" }
 | 
			
		||||
iris = { module = "maven.modrinth:iris", version.ref = "iris" }
 | 
			
		||||
jei-api = { module = "mezz.jei:jei-1.20.4-common-api", version.ref = "jei" }
 | 
			
		||||
jei-fabric = { module = "mezz.jei:jei-1.20.4-fabric", version.ref = "jei" }
 | 
			
		||||
jei-forge = { module = "mezz.jei:jei-1.20.4-forge", version.ref = "jei" }
 | 
			
		||||
jei-api = { module = "mezz.jei:jei-1.20.1-common-api", version.ref = "jei" }
 | 
			
		||||
jei-fabric = { module = "mezz.jei:jei-1.20.1-fabric", version.ref = "jei" }
 | 
			
		||||
jei-forge = { module = "mezz.jei:jei-1.20.1-forge", version.ref = "jei" }
 | 
			
		||||
mixin = { module = "org.spongepowered:mixin", version.ref = "mixin" }
 | 
			
		||||
modmenu = { module = "com.terraformersmc:modmenu", version.ref = "modmenu" }
 | 
			
		||||
moreRed = { module = "commoble.morered:morered-1.20.1", version.ref = "moreRed" }
 | 
			
		||||
@@ -145,13 +150,15 @@ errorProne-core = { module = "com.google.errorprone:error_prone_core", version.r
 | 
			
		||||
errorProne-plugin = { module = "net.ltgt.gradle:gradle-errorprone-plugin", version.ref = "errorProne-plugin" }
 | 
			
		||||
errorProne-testHelpers = { module = "com.google.errorprone:error_prone_test_helpers", version.ref = "errorProne-core" }
 | 
			
		||||
fabric-loom = { module = "net.fabricmc:fabric-loom", version.ref = "fabric-loom" }
 | 
			
		||||
forgeGradle = { module = "net.minecraftforge.gradle:ForgeGradle", version.ref = "forgeGradle" }
 | 
			
		||||
ideaExt = { module = "gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext", version.ref = "ideaExt" }
 | 
			
		||||
kotlin-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
 | 
			
		||||
librarian = { module = "org.parchmentmc:librarian", version.ref = "librarian" }
 | 
			
		||||
minotaur = { module = "com.modrinth.minotaur:Minotaur", version.ref = "minotaur" }
 | 
			
		||||
neoGradle-userdev = { module = "net.neoforged.gradle:userdev", version.ref = "neoGradle" }
 | 
			
		||||
nullAway = { module = "com.uber.nullaway:nullaway", version.ref = "nullAway" }
 | 
			
		||||
spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" }
 | 
			
		||||
teavm-classlib = { module = "org.teavm:teavm-classlib", version.ref = "teavm" }
 | 
			
		||||
teavm-core = { module = "org.teavm:teavm-core", version.ref = "teavm" }
 | 
			
		||||
teavm-jso = { module = "org.teavm:teavm-jso", version.ref = "teavm" }
 | 
			
		||||
teavm-jso-apis = { module = "org.teavm:teavm-jso-apis", version.ref = "teavm" }
 | 
			
		||||
teavm-jso-impl = { module = "org.teavm:teavm-jso-impl", version.ref = "teavm" }
 | 
			
		||||
@@ -163,9 +170,11 @@ vanillaExtract = { module = "cc.tweaked.vanilla-extract:plugin", version.ref = "
 | 
			
		||||
yarn = { module = "net.fabricmc:yarn", version.ref = "yarn" }
 | 
			
		||||
 | 
			
		||||
[plugins]
 | 
			
		||||
forgeGradle = { id = "net.minecraftforge.gradle", version.ref = "forgeGradle" }
 | 
			
		||||
githubRelease = { id = "com.github.breadmoirai.github-release", version.ref = "githubRelease" }
 | 
			
		||||
gradleVersions = { id = "com.github.ben-manes.versions", version.ref = "gradleVersions" }
 | 
			
		||||
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
 | 
			
		||||
librarian = { id = "org.parchmentmc.librarian.forgegradle", version.ref = "librarian" }
 | 
			
		||||
taskTree = { id = "com.dorongold.task-tree", version.ref = "taskTree" }
 | 
			
		||||
versionCatalogUpdate = { id = "nl.littlerobots.version-catalog-update", version.ref = "versionCatalogUpdate" }
 | 
			
		||||
 | 
			
		||||
@@ -176,7 +185,7 @@ kotlin = ["kotlin-stdlib", "kotlin-coroutines"]
 | 
			
		||||
# Minecraft
 | 
			
		||||
externalMods-common = ["jei-api", "nightConfig-core", "nightConfig-toml"]
 | 
			
		||||
externalMods-forge-compile = ["moreRed", "oculus", "jei-api"]
 | 
			
		||||
externalMods-forge-runtime = []
 | 
			
		||||
externalMods-forge-runtime = ["jei-forge"]
 | 
			
		||||
externalMods-fabric-compile = ["fabricPermissions", "iris", "jei-api", "rei-api", "rei-builtin"]
 | 
			
		||||
externalMods-fabric-runtime = ["jei-fabric", "modmenu"]
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								gradle/wrapper/gradle-wrapper.jar
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								gradle/wrapper/gradle-wrapper.jar
									
									
									
									
										vendored
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							@@ -1,6 +1,6 @@
 | 
			
		||||
distributionBase=GRADLE_USER_HOME
 | 
			
		||||
distributionPath=wrapper/dists
 | 
			
		||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
 | 
			
		||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
 | 
			
		||||
networkTimeout=10000
 | 
			
		||||
validateDistributionUrl=true
 | 
			
		||||
zipStoreBase=GRADLE_USER_HOME
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										7
									
								
								gradlew
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										7
									
								
								gradlew
									
									
									
									
										vendored
									
									
								
							@@ -15,6 +15,8 @@
 | 
			
		||||
# See the License for the specific language governing permissions and
 | 
			
		||||
# limitations under the License.
 | 
			
		||||
#
 | 
			
		||||
# SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
##############################################################################
 | 
			
		||||
#
 | 
			
		||||
@@ -55,7 +57,7 @@
 | 
			
		||||
#       Darwin, MinGW, and NonStop.
 | 
			
		||||
#
 | 
			
		||||
#   (3) This script is generated from the Groovy template
 | 
			
		||||
#       https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
 | 
			
		||||
#       https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
 | 
			
		||||
#       within the Gradle project.
 | 
			
		||||
#
 | 
			
		||||
#       You can find Gradle at https://github.com/gradle/gradle/.
 | 
			
		||||
@@ -84,7 +86,8 @@ done
 | 
			
		||||
# shellcheck disable=SC2034
 | 
			
		||||
APP_BASE_NAME=${0##*/}
 | 
			
		||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
 | 
			
		||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
 | 
			
		||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
 | 
			
		||||
' "$PWD" ) || exit
 | 
			
		||||
 | 
			
		||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
 | 
			
		||||
MAX_FD=maximum
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								gradlew.bat
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								gradlew.bat
									
									
									
									
										vendored
									
									
								
							@@ -13,6 +13,8 @@
 | 
			
		||||
@rem See the License for the specific language governing permissions and
 | 
			
		||||
@rem limitations under the License.
 | 
			
		||||
@rem
 | 
			
		||||
@rem SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
@rem
 | 
			
		||||
 | 
			
		||||
@if "%DEBUG%"=="" @echo off
 | 
			
		||||
@rem ##########################################################################
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,43 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2022 The CC: Tweaked Developers
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
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 dan200.computercraft.impl.client.ComputerCraftAPIClientService;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The public API for client-only code.
 | 
			
		||||
 *
 | 
			
		||||
 * @see dan200.computercraft.api.ComputerCraftAPI The main API
 | 
			
		||||
 */
 | 
			
		||||
public final class ComputerCraftAPIClient {
 | 
			
		||||
    private ComputerCraftAPIClient() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Register a {@link TurtleUpgradeModeller} for a class of turtle upgrades.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * This may be called at any point after registry creation, though it is recommended to call it within your client
 | 
			
		||||
     * setup step.
 | 
			
		||||
     *
 | 
			
		||||
     * @param serialiser The turtle upgrade serialiser.
 | 
			
		||||
     * @param modeller   The upgrade modeller.
 | 
			
		||||
     * @param <T>        The type of the turtle upgrade.
 | 
			
		||||
     * @deprecated This method can lead to confusing load behaviour on Forge. Use
 | 
			
		||||
     * {@code dan200.computercraft.api.client.FabricComputerCraftAPIClient#registerTurtleUpgradeModeller} on Fabric, or
 | 
			
		||||
     * {@code dan200.computercraft.api.client.turtle.RegisterTurtleModellersEvent} on Forge.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated(forRemoval = true)
 | 
			
		||||
    public static <T extends ITurtleUpgrade> void registerTurtleUpgradeModeller(TurtleUpgradeSerialiser<T> serialiser, TurtleUpgradeModeller<T> modeller) {
 | 
			
		||||
        // TODO(1.20.4): Remove this
 | 
			
		||||
        getInstance().registerTurtleUpgradeModeller(serialiser, modeller);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static ComputerCraftAPIClientService getInstance() {
 | 
			
		||||
        return ComputerCraftAPIClientService.get();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -5,7 +5,7 @@
 | 
			
		||||
package dan200.computercraft.api.client.turtle;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A functional interface to register a {@link TurtleUpgradeModeller} for a class of turtle upgrades.
 | 
			
		||||
@@ -22,5 +22,5 @@ public interface RegisterTurtleUpgradeModeller {
 | 
			
		||||
     * @param modeller   The upgrade modeller.
 | 
			
		||||
     * @param <T>        The type of the turtle upgrade.
 | 
			
		||||
     */
 | 
			
		||||
    <T extends ITurtleUpgrade> void register(UpgradeSerialiser<T> serialiser, TurtleUpgradeModeller<T> modeller);
 | 
			
		||||
    <T extends ITurtleUpgrade> void register(TurtleUpgradeSerialiser<T> serialiser, TurtleUpgradeModeller<T> modeller);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@ 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 net.minecraft.client.resources.model.ModelResourceLocation;
 | 
			
		||||
import net.minecraft.client.resources.model.UnbakedModel;
 | 
			
		||||
import net.minecraft.nbt.CompoundTag;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
@@ -30,15 +31,30 @@ public interface TurtleUpgradeModeller<T extends ITurtleUpgrade> {
 | 
			
		||||
    /**
 | 
			
		||||
     * Obtain the model to be used when rendering a turtle peripheral.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * When the current turtle is {@literal null}, this function should be constant for a given upgrade, side and data.
 | 
			
		||||
     * 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 turtle  Access to the turtle that the upgrade resides on. This will be null when getting item models, unless
 | 
			
		||||
     *                {@link #getModel(ITurtleUpgrade, CompoundTag, TurtleSide)} is overriden.
 | 
			
		||||
     * @param side    Which side of the turtle (left or right) the upgrade resides on.
 | 
			
		||||
     * @param data    Upgrade data instance for current turtle side.
 | 
			
		||||
     * @return The model that you wish to be used to render your upgrade.
 | 
			
		||||
     */
 | 
			
		||||
    TransformedModel getModel(T upgrade, @Nullable ITurtleAccess turtle, TurtleSide side, CompoundTag data);
 | 
			
		||||
    TransformedModel getModel(T upgrade, @Nullable ITurtleAccess turtle, TurtleSide side);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Obtain the model to be used when rendering a turtle peripheral.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * This is used when rendering the turtle's item model, and so no {@link ITurtleAccess} is available.
 | 
			
		||||
     *
 | 
			
		||||
     * @param upgrade The upgrade that you're getting the model for.
 | 
			
		||||
     * @param data    Upgrade data instance for current turtle side.
 | 
			
		||||
     * @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.
 | 
			
		||||
     */
 | 
			
		||||
    default TransformedModel getModel(T upgrade, CompoundTag data, TurtleSide side) {
 | 
			
		||||
        return getModel(upgrade, (ITurtleAccess) null, side);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a list of models that this turtle modeller depends on.
 | 
			
		||||
@@ -69,6 +85,19 @@ public interface TurtleUpgradeModeller<T extends ITurtleUpgrade> {
 | 
			
		||||
        return (TurtleUpgradeModeller<T>) TurtleUpgradeModellers.UPGRADE_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) {
 | 
			
		||||
        // TODO(1.21.0): Remove this.
 | 
			
		||||
        return sided((ResourceLocation) left, right);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Construct a {@link TurtleUpgradeModeller} which has a single model for the left and right side.
 | 
			
		||||
     *
 | 
			
		||||
@@ -80,7 +109,7 @@ public interface TurtleUpgradeModeller<T extends ITurtleUpgrade> {
 | 
			
		||||
    static <T extends ITurtleUpgrade> TurtleUpgradeModeller<T> sided(ResourceLocation left, ResourceLocation right) {
 | 
			
		||||
        return new TurtleUpgradeModeller<>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public TransformedModel getModel(T upgrade, @Nullable ITurtleAccess turtle, TurtleSide side, CompoundTag data) {
 | 
			
		||||
            public TransformedModel getModel(T upgrade, @Nullable ITurtleAccess turtle, TurtleSide side) {
 | 
			
		||||
                return TransformedModel.of(side == TurtleSide.LEFT ? left : right);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,7 @@ import dan200.computercraft.api.turtle.TurtleSide;
 | 
			
		||||
import dan200.computercraft.impl.client.ClientPlatformHelper;
 | 
			
		||||
import net.minecraft.client.Minecraft;
 | 
			
		||||
import net.minecraft.nbt.CompoundTag;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import org.joml.Matrix4f;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
@@ -36,8 +37,16 @@ final class TurtleUpgradeModellers {
 | 
			
		||||
 | 
			
		||||
    private static final class UpgradeItemModeller implements TurtleUpgradeModeller<ITurtleUpgrade> {
 | 
			
		||||
        @Override
 | 
			
		||||
        public TransformedModel getModel(ITurtleUpgrade upgrade, @Nullable ITurtleAccess turtle, TurtleSide side, CompoundTag data) {
 | 
			
		||||
            var stack = upgrade.getUpgradeItem(data);
 | 
			
		||||
        public TransformedModel getModel(ITurtleUpgrade upgrade, @Nullable ITurtleAccess turtle, TurtleSide side) {
 | 
			
		||||
            return getModel(turtle == null ? upgrade.getCraftingItem() : upgrade.getUpgradeItem(turtle.getUpgradeNBTData(side)), side);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public TransformedModel getModel(ITurtleUpgrade upgrade, CompoundTag data, TurtleSide side) {
 | 
			
		||||
            return getModel(upgrade.getUpgradeItem(data), side);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private TransformedModel getModel(ItemStack stack, TurtleSide side) {
 | 
			
		||||
            var model = Minecraft.getInstance().getItemRenderer().getItemModelShaper().getItemModel(stack);
 | 
			
		||||
            if (stack.hasFoil()) model = ClientPlatformHelper.get().createdFoiledModel(model);
 | 
			
		||||
            return new TransformedModel(model, side == TurtleSide.LEFT ? leftTransform : rightTransform);
 | 
			
		||||
 
 | 
			
		||||
@@ -4,34 +4,35 @@
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.impl.client;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.client.ComputerCraftAPIClient;
 | 
			
		||||
import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller;
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.impl.Services;
 | 
			
		||||
import org.jetbrains.annotations.ApiStatus;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Backing interface for CC's client-side API.
 | 
			
		||||
 * Backing interface for {@link ComputerCraftAPIClient}
 | 
			
		||||
 * <p>
 | 
			
		||||
 * Do <strong>NOT</strong> directly reference this class. It exists for internal use by the API.
 | 
			
		||||
 */
 | 
			
		||||
@ApiStatus.Internal
 | 
			
		||||
public interface FabricComputerCraftAPIClientService {
 | 
			
		||||
    static FabricComputerCraftAPIClientService get() {
 | 
			
		||||
public interface ComputerCraftAPIClientService {
 | 
			
		||||
    static ComputerCraftAPIClientService get() {
 | 
			
		||||
        var instance = Instance.INSTANCE;
 | 
			
		||||
        return instance == null ? Services.raise(FabricComputerCraftAPIClientService.class, Instance.ERROR) : instance;
 | 
			
		||||
        return instance == null ? Services.raise(ComputerCraftAPIClientService.class, Instance.ERROR) : instance;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    <T extends ITurtleUpgrade> void registerTurtleUpgradeModeller(UpgradeSerialiser<T> serialiser, TurtleUpgradeModeller<T> modeller);
 | 
			
		||||
    <T extends ITurtleUpgrade> void registerTurtleUpgradeModeller(TurtleUpgradeSerialiser<T> serialiser, TurtleUpgradeModeller<T> modeller);
 | 
			
		||||
 | 
			
		||||
    final class Instance {
 | 
			
		||||
        static final @Nullable FabricComputerCraftAPIClientService INSTANCE;
 | 
			
		||||
        static final @Nullable ComputerCraftAPIClientService INSTANCE;
 | 
			
		||||
        static final @Nullable Throwable ERROR;
 | 
			
		||||
 | 
			
		||||
        static {
 | 
			
		||||
            var helper = Services.tryLoad(FabricComputerCraftAPIClientService.class);
 | 
			
		||||
            var helper = Services.tryLoad(ComputerCraftAPIClientService.class);
 | 
			
		||||
            INSTANCE = helper.instance();
 | 
			
		||||
            ERROR = helper.error();
 | 
			
		||||
        }
 | 
			
		||||
@@ -4,9 +4,11 @@
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.component.ComputerComponent;
 | 
			
		||||
import dan200.computercraft.api.filesystem.Mount;
 | 
			
		||||
import dan200.computercraft.api.filesystem.WritableMount;
 | 
			
		||||
import dan200.computercraft.api.lua.GenericSource;
 | 
			
		||||
import dan200.computercraft.api.lua.IComputerSystem;
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaAPI;
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaAPIFactory;
 | 
			
		||||
import dan200.computercraft.api.media.IMedia;
 | 
			
		||||
@@ -165,7 +167,20 @@ public final class ComputerCraftAPI {
 | 
			
		||||
     * Register a custom {@link ILuaAPI}, which may be added onto all computers without requiring a peripheral.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * Before implementing this interface, consider alternative methods of providing methods. It is generally preferred
 | 
			
		||||
     * to use peripherals to provide functionality to users.
 | 
			
		||||
     * to use peripherals to provide functionality to users. If an API is <em>required</em>, you may want to consider
 | 
			
		||||
     * using {@link ILuaAPI#getModuleName()} to expose this library as a module instead of as a global.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * This may be used with {@link IComputerSystem#getComponent(ComputerComponent)} to only attach APIs to specific
 | 
			
		||||
     * computers. For example, one can add an additional API just to turtles with the following code:
 | 
			
		||||
     *
 | 
			
		||||
     * <pre>{@code
 | 
			
		||||
     * ComputerCraftAPI.registerAPIFactory(computer -> {
 | 
			
		||||
     *   // Read the turtle component.
 | 
			
		||||
     *   var turtle = computer.getComponent(ComputerComponents.TURTLE);
 | 
			
		||||
     *   // If present then add our API.
 | 
			
		||||
     *   return turtle == null ? null : new MyCustomTurtleApi(turtle);
 | 
			
		||||
     * });
 | 
			
		||||
     * }</pre>
 | 
			
		||||
     *
 | 
			
		||||
     * @param factory The factory for your API subclass.
 | 
			
		||||
     * @see ILuaAPIFactory
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,24 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2024 The CC: Tweaked Developers
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.component;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.commands.CommandSourceStack;
 | 
			
		||||
import org.jetbrains.annotations.ApiStatus;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A computer which has permission to perform administrative/op commands, such as the command computer.
 | 
			
		||||
 */
 | 
			
		||||
@ApiStatus.NonExtendable
 | 
			
		||||
public interface AdminComputer {
 | 
			
		||||
    /**
 | 
			
		||||
     * The permission level that this computer can operate at.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The permission level for this computer.
 | 
			
		||||
     * @see CommandSourceStack#hasPermission(int)
 | 
			
		||||
     */
 | 
			
		||||
    default int permissionLevel() {
 | 
			
		||||
        return 2;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,48 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2024 The CC: Tweaked Developers
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.component;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.lua.IComputerSystem;
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaAPIFactory;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A component attached to a computer.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * Components provide a mechanism to attach additional data to a computer, that can then be queried with
 | 
			
		||||
 * {@link IComputerSystem#getComponent(ComputerComponent)}.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * This is largely designed for {@linkplain ILuaAPIFactory custom APIs}, allowing APIs to read additional properties
 | 
			
		||||
 * of the computer, such as its position.
 | 
			
		||||
 *
 | 
			
		||||
 * @param <T> The type of this component.
 | 
			
		||||
 * @see ComputerComponents The built-in components.
 | 
			
		||||
 */
 | 
			
		||||
@SuppressWarnings("UnusedTypeParameter")
 | 
			
		||||
public final class ComputerComponent<T> {
 | 
			
		||||
    private final String id;
 | 
			
		||||
 | 
			
		||||
    private ComputerComponent(String id) {
 | 
			
		||||
        this.id = id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new computer component.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * Mods typically will not need to create their own components.
 | 
			
		||||
     *
 | 
			
		||||
     * @param namespace The namespace of this component. This should be the mod id.
 | 
			
		||||
     * @param id        The unique id of this component.
 | 
			
		||||
     * @param <T>       The component
 | 
			
		||||
     * @return The newly created component.
 | 
			
		||||
     */
 | 
			
		||||
    public static <T> ComputerComponent<T> create(String namespace, String id) {
 | 
			
		||||
        return new ComputerComponent<>(namespace + ":" + id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return "ComputerComponent(" + id + ")";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,29 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2024 The CC: Tweaked Developers
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.component;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI;
 | 
			
		||||
import dan200.computercraft.api.pocket.IPocketAccess;
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleAccess;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The {@link ComputerComponent}s provided by ComputerCraft.
 | 
			
		||||
 */
 | 
			
		||||
public class ComputerComponents {
 | 
			
		||||
    /**
 | 
			
		||||
     * The {@link ITurtleAccess} associated with a turtle.
 | 
			
		||||
     */
 | 
			
		||||
    public static final ComputerComponent<ITurtleAccess> TURTLE = ComputerComponent.create(ComputerCraftAPI.MOD_ID, "turtle");
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The {@link IPocketAccess} associated with a pocket computer.
 | 
			
		||||
     */
 | 
			
		||||
    public static final ComputerComponent<IPocketAccess> POCKET = ComputerComponent.create(ComputerCraftAPI.MOD_ID, "pocket");
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This component is only present on "command computers", and other computers with admin capabilities.
 | 
			
		||||
     */
 | 
			
		||||
    public static final ComputerComponent<AdminComputer> ADMIN_COMPUTER = ComputerComponent.create(ComputerCraftAPI.MOD_ID, "admin_computer");
 | 
			
		||||
}
 | 
			
		||||
@@ -13,7 +13,7 @@ import java.util.Map;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * An item detail provider for {@link ItemStack}'s whose {@link Item} has a specific type.
 | 
			
		||||
 * An item detail provider for {@link ItemStack}s whose {@link Item} has a specific type.
 | 
			
		||||
 *
 | 
			
		||||
 * @param <T> The type the stack's item must have.
 | 
			
		||||
 */
 | 
			
		||||
@@ -22,7 +22,7 @@ public abstract class BasicItemDetailProvider<T> implements DetailProvider<ItemS
 | 
			
		||||
    private final @Nullable String namespace;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new item detail provider. Meta will be inserted into a new sub-map named as per {@code namespace}.
 | 
			
		||||
     * Create a new item detail provider. Details will be inserted into a new sub-map named as per {@code namespace}.
 | 
			
		||||
     *
 | 
			
		||||
     * @param itemType  The type the stack's item must have.
 | 
			
		||||
     * @param namespace The namespace to use for this provider.
 | 
			
		||||
@@ -34,7 +34,7 @@ public abstract class BasicItemDetailProvider<T> implements DetailProvider<ItemS
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new item detail provider. Meta will be inserted directly into the results.
 | 
			
		||||
     * Create a new item detail provider. Details will be inserted directly into the results.
 | 
			
		||||
     *
 | 
			
		||||
     * @param itemType The type the stack's item must have.
 | 
			
		||||
     */
 | 
			
		||||
@@ -53,21 +53,18 @@ public abstract class BasicItemDetailProvider<T> implements DetailProvider<ItemS
 | 
			
		||||
     * @param stack The item stack to provide details for.
 | 
			
		||||
     * @param item  The item to provide details for.
 | 
			
		||||
     */
 | 
			
		||||
    public abstract void provideDetails(
 | 
			
		||||
        Map<? super String, Object> data, ItemStack stack, T item
 | 
			
		||||
    );
 | 
			
		||||
    public abstract void provideDetails(Map<? super String, Object> data, ItemStack stack, T item);
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void provideDetails(Map<? super String, Object> data, ItemStack stack) {
 | 
			
		||||
    public final void provideDetails(Map<? super String, Object> data, ItemStack stack) {
 | 
			
		||||
        var item = stack.getItem();
 | 
			
		||||
        if (!itemType.isInstance(item)) return;
 | 
			
		||||
 | 
			
		||||
        // If `namespace` is specified, insert into a new data map instead of the existing one.
 | 
			
		||||
        Map<? super String, Object> child = namespace == null ? data : new HashMap<>();
 | 
			
		||||
 | 
			
		||||
        if (namespace == null) {
 | 
			
		||||
            provideDetails(data, stack, itemType.cast(item));
 | 
			
		||||
        } else {
 | 
			
		||||
            Map<? super String, Object> child = new HashMap<>();
 | 
			
		||||
            provideDetails(child, stack, itemType.cast(item));
 | 
			
		||||
 | 
			
		||||
        if (namespace != null) {
 | 
			
		||||
            data.put(namespace, child);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,7 @@ public interface DetailRegistry<T> {
 | 
			
		||||
     * @param provider The detail provider to register.
 | 
			
		||||
     * @see DetailProvider
 | 
			
		||||
     */
 | 
			
		||||
    void addProvider(DetailProvider<T> provider);
 | 
			
		||||
    void addProvider(DetailProvider<? super T> provider);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Compute basic details about an object. This is cheaper than computing all details operation, and so is suitable
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,59 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2017 The CC: Tweaked Developers
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.component.ComputerComponent;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IComputerAccess;
 | 
			
		||||
import net.minecraft.core.BlockPos;
 | 
			
		||||
import net.minecraft.server.level.ServerLevel;
 | 
			
		||||
import org.jetbrains.annotations.ApiStatus;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * An interface passed to {@link ILuaAPIFactory} in order to provide additional information
 | 
			
		||||
 * about a computer.
 | 
			
		||||
 */
 | 
			
		||||
@ApiStatus.NonExtendable
 | 
			
		||||
public interface IComputerSystem extends IComputerAccess {
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the level this computer is currently in.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * This method is not guaranteed to remain the same (even for stationary computers).
 | 
			
		||||
     *
 | 
			
		||||
     * @return The computer's current level.
 | 
			
		||||
     */
 | 
			
		||||
    ServerLevel getLevel();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the position this computer is currently at.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * This method is not guaranteed to remain the same (even for stationary computers).
 | 
			
		||||
     *
 | 
			
		||||
     * @return The computer's current position.
 | 
			
		||||
     */
 | 
			
		||||
    BlockPos getPosition();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the label for this computer.
 | 
			
		||||
     *
 | 
			
		||||
     * @return This computer's label, or {@code null} if it is not set.
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    String getLabel();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a component attached to this computer.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * No component is guaranteed to be on a computer, and so this method should always be guarded with a null check.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * This method will always return the same value for a given component, and so may be cached.
 | 
			
		||||
     *
 | 
			
		||||
     * @param component The component to query.
 | 
			
		||||
     * @param <T>       The type of the component.
 | 
			
		||||
     * @return The component, if present.
 | 
			
		||||
     */
 | 
			
		||||
    <T> @Nullable T getComponent(ComputerComponent<T> component);
 | 
			
		||||
}
 | 
			
		||||
@@ -4,13 +4,15 @@
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Construct an {@link ILuaAPI} for a specific computer.
 | 
			
		||||
 * Construct an {@link ILuaAPI} for a computer.
 | 
			
		||||
 *
 | 
			
		||||
 * @see ILuaAPI
 | 
			
		||||
 * @see dan200.computercraft.api.ComputerCraftAPI#registerAPIFactory(ILuaAPIFactory)
 | 
			
		||||
 * @see ComputerCraftAPI#registerAPIFactory(ILuaAPIFactory)
 | 
			
		||||
 */
 | 
			
		||||
@FunctionalInterface
 | 
			
		||||
public interface ILuaAPIFactory {
 | 
			
		||||
@@ -0,0 +1,92 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2018 The CC: Tweaked Developers
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.network.wired;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheral;
 | 
			
		||||
import org.jetbrains.annotations.ApiStatus;
 | 
			
		||||
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A wired network is composed of one of more {@link WiredNode}s, a set of connections between them, and a series
 | 
			
		||||
 * of peripherals.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * Networks from a connected graph. This means there is some path between all nodes on the network. Further more, if
 | 
			
		||||
 * there is some path between two nodes then they must be on the same network. {@link WiredNetwork} will automatically
 | 
			
		||||
 * handle the merging and splitting of networks (and thus changing of available nodes and peripherals) as connections
 | 
			
		||||
 * change.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * This does mean one can not rely on the network remaining consistent between subsequent operations. Consequently,
 | 
			
		||||
 * it is generally preferred to use the methods provided by {@link WiredNode}.
 | 
			
		||||
 *
 | 
			
		||||
 * @see WiredNode#getNetwork()
 | 
			
		||||
 */
 | 
			
		||||
@ApiStatus.NonExtendable
 | 
			
		||||
public interface WiredNetwork {
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a connection between two nodes.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * This should only be used on the server thread.
 | 
			
		||||
     *
 | 
			
		||||
     * @param left  The first node to connect
 | 
			
		||||
     * @param right The second node to connect
 | 
			
		||||
     * @return {@code true} if a connection was created or {@code false} if the connection already exists.
 | 
			
		||||
     * @throws IllegalStateException    If neither node is on the network.
 | 
			
		||||
     * @throws IllegalArgumentException If {@code left} and {@code right} are equal.
 | 
			
		||||
     * @see WiredNode#connectTo(WiredNode)
 | 
			
		||||
     * @see WiredNetwork#connect(WiredNode, WiredNode)
 | 
			
		||||
     * @deprecated Use {@link WiredNode#connectTo(WiredNode)}
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    boolean connect(WiredNode left, WiredNode right);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Destroy a connection between this node and another.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * This should only be used on the server thread.
 | 
			
		||||
     *
 | 
			
		||||
     * @param left  The first node in the connection.
 | 
			
		||||
     * @param right The second node in the connection.
 | 
			
		||||
     * @return {@code true} if a connection was destroyed or {@code false} if no connection exists.
 | 
			
		||||
     * @throws IllegalArgumentException If either node is not on the network.
 | 
			
		||||
     * @throws IllegalArgumentException If {@code left} and {@code right} are equal.
 | 
			
		||||
     * @see WiredNode#disconnectFrom(WiredNode)
 | 
			
		||||
     * @see WiredNetwork#connect(WiredNode, WiredNode)
 | 
			
		||||
     * @deprecated Use {@link WiredNode#disconnectFrom(WiredNode)}
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    boolean disconnect(WiredNode left, WiredNode right);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sever all connections this node has, removing it from this network.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * This should only be used on the server thread. You should only call this on nodes
 | 
			
		||||
     * that your network element owns.
 | 
			
		||||
     *
 | 
			
		||||
     * @param node The node to remove
 | 
			
		||||
     * @return Whether this node was removed from the network. One cannot remove a node from a network where it is the
 | 
			
		||||
     * only element.
 | 
			
		||||
     * @throws IllegalArgumentException If the node is not in the network.
 | 
			
		||||
     * @see WiredNode#remove()
 | 
			
		||||
     * @deprecated Use {@link WiredNode#remove()}
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    boolean remove(WiredNode node);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Update the peripherals a node provides.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * This should only be used on the server thread. You should only call this on nodes
 | 
			
		||||
     * that your network element owns.
 | 
			
		||||
     *
 | 
			
		||||
     * @param node        The node to attach peripherals for.
 | 
			
		||||
     * @param peripherals The new peripherals for this node.
 | 
			
		||||
     * @throws IllegalArgumentException If the node is not in the network.
 | 
			
		||||
     * @see WiredNode#updatePeripherals(Map)
 | 
			
		||||
     * @deprecated Use {@link WiredNode#updatePeripherals(Map)}
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    void updatePeripherals(WiredNode node, Map<String, IPeripheral> peripherals);
 | 
			
		||||
}
 | 
			
		||||
@@ -11,7 +11,7 @@ import org.jetbrains.annotations.ApiStatus;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A single node on a wired network.
 | 
			
		||||
 * Wired nodes act as a layer between {@link WiredElement}s and {@link WiredNetwork}s.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * Firstly, a node acts as a packet network, capable of sending and receiving modem messages to connected nodes. These
 | 
			
		||||
 * methods may be safely used on any thread.
 | 
			
		||||
@@ -32,6 +32,18 @@ public interface WiredNode extends PacketNetwork {
 | 
			
		||||
     */
 | 
			
		||||
    WiredElement getElement();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The network this node is currently connected to. Note that this may change
 | 
			
		||||
     * after any network operation, so it should not be cached.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * This should only be used on the server thread.
 | 
			
		||||
     *
 | 
			
		||||
     * @return This node's network.
 | 
			
		||||
     * @deprecated Use the connect/disconnect/remove methods on {@link WiredNode}.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    WiredNetwork getNetwork();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a connection from this node to another.
 | 
			
		||||
     * <p>
 | 
			
		||||
 
 | 
			
		||||
@@ -8,12 +8,10 @@ import dan200.computercraft.api.network.PacketSender;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * An object on a wired network capable of sending packets.
 | 
			
		||||
 * An object on a {@link WiredNetwork} capable of sending packets.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * Unlike a regular {@link PacketSender}, this must be associated with the node you are attempting to
 | 
			
		||||
 * to send the packet from.
 | 
			
		||||
 *
 | 
			
		||||
 * @see WiredElement
 | 
			
		||||
 */
 | 
			
		||||
public interface WiredSender extends PacketSender {
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -4,17 +4,39 @@
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.pocket;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheral;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeBase;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeData;
 | 
			
		||||
import net.minecraft.nbt.CompoundTag;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.server.level.ServerLevel;
 | 
			
		||||
import net.minecraft.world.entity.Entity;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import net.minecraft.world.phys.Vec3;
 | 
			
		||||
import org.jetbrains.annotations.ApiStatus;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Wrapper class for pocket computers.
 | 
			
		||||
 */
 | 
			
		||||
@ApiStatus.NonExtendable
 | 
			
		||||
public interface IPocketAccess {
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the level in which the pocket computer exists.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The pocket computer's level.
 | 
			
		||||
     */
 | 
			
		||||
    ServerLevel getLevel();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the position of the pocket computer.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The pocket computer's position.
 | 
			
		||||
     */
 | 
			
		||||
    Vec3 getPosition();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the entity holding this item.
 | 
			
		||||
     * <p>
 | 
			
		||||
@@ -61,6 +83,26 @@ public interface IPocketAccess {
 | 
			
		||||
     */
 | 
			
		||||
    void setLight(int colour);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the currently equipped upgrade.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The currently equipped upgrade.
 | 
			
		||||
     * @see #getUpgradeNBTData()
 | 
			
		||||
     * @see #setUpgrade(UpgradeData)
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    UpgradeData<IPocketUpgrade> getUpgrade();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Set the upgrade for this pocket computer, also updating the item stack.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * Note this method is not thread safe - it must be called from the server thread.
 | 
			
		||||
     *
 | 
			
		||||
     * @param upgrade The new upgrade to set it to, may be {@code null}.
 | 
			
		||||
     * @see #getUpgrade()
 | 
			
		||||
     */
 | 
			
		||||
    void setUpgrade(@Nullable UpgradeData<IPocketUpgrade> upgrade);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the upgrade-specific NBT.
 | 
			
		||||
     * <p>
 | 
			
		||||
@@ -70,6 +112,7 @@ public interface IPocketAccess {
 | 
			
		||||
     * @see #updateUpgradeNBTData()
 | 
			
		||||
     * @see UpgradeBase#getUpgradeItem(CompoundTag)
 | 
			
		||||
     * @see UpgradeBase#getUpgradeData(ItemStack)
 | 
			
		||||
     * @see #getUpgrade()
 | 
			
		||||
     */
 | 
			
		||||
    CompoundTag getUpgradeNBTData();
 | 
			
		||||
 | 
			
		||||
@@ -87,4 +130,13 @@ public interface IPocketAccess {
 | 
			
		||||
     * entity} changes.
 | 
			
		||||
     */
 | 
			
		||||
    void invalidatePeripheral();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a list of all upgrades for the pocket computer.
 | 
			
		||||
     *
 | 
			
		||||
     * @return A collection of all upgrade names.
 | 
			
		||||
     * @deprecated This is a relic of a previous API, which no longer makes sense with newer versions of ComputerCraft.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated(forRemoval = true)
 | 
			
		||||
    Map<ResourceLocation, IPeripheral> getUpgrades();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,10 +6,6 @@ package dan200.computercraft.api.pocket;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheral;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeBase;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.impl.ComputerCraftAPIService;
 | 
			
		||||
import net.minecraft.core.Registry;
 | 
			
		||||
import net.minecraft.resources.ResourceKey;
 | 
			
		||||
import net.minecraft.world.level.Level;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
@@ -17,46 +13,16 @@ import javax.annotation.Nullable;
 | 
			
		||||
/**
 | 
			
		||||
 * A peripheral which can be equipped to the back side of a pocket computer.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * Pocket upgrades are defined in two stages. First, one creates a {@link IPocketUpgrade} subclass and corresponding
 | 
			
		||||
 * {@link UpgradeSerialiser} instance, which are then registered in a registry.
 | 
			
		||||
 * Pocket upgrades are defined in two stages. First, on creates a {@link IPocketUpgrade} subclass and corresponding
 | 
			
		||||
 * {@link PocketUpgradeSerialiser} instance, which are then registered in a Forge registry.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * You then write a JSON file in your mod's {@literal data/} folder. This is then parsed when the world is loaded, and
 | 
			
		||||
 * the upgrade automatically registered. It is recommended this is done via {@linkplain PocketUpgradeDataProvider data
 | 
			
		||||
 * generators}.
 | 
			
		||||
 * the upgrade registered internally. See the documentation in {@link PocketUpgradeSerialiser} for details on this process
 | 
			
		||||
 * and where files should be located.
 | 
			
		||||
 *
 | 
			
		||||
 * <h2>Example</h2>
 | 
			
		||||
 * <pre>{@code
 | 
			
		||||
 * // We use Forge's DeferredRegister to register our serialiser. Fabric mods may register their serialiser directly.
 | 
			
		||||
 * static final DeferredRegister<UpgradeSerialiser<? extends IPocketUpgrade>> SERIALISERS = DeferredRegister.create(IPocketUpgrade.serialiserRegistryKey(), "my_mod");
 | 
			
		||||
 *
 | 
			
		||||
 * // Register a new upgrade serialiser called "my_upgrade".
 | 
			
		||||
 * public static final RegistryObject<UpgradeSerialiser<MyUpgrade>> MY_UPGRADE =
 | 
			
		||||
 *     SERIALISERS.register("my_upgrade", () -> UpgradeSerialiser.simple(MyUpgrade::new));
 | 
			
		||||
 *
 | 
			
		||||
 * // Then in your constructor
 | 
			
		||||
 * SERIALISERS.register(bus);
 | 
			
		||||
 * }</pre>
 | 
			
		||||
 * <p>
 | 
			
		||||
 * We can then define a new upgrade using JSON by placing the following in
 | 
			
		||||
 * {@code data/<my_mod>/computercraft/pocket_upgrades/<my_upgrade_id>.json}.
 | 
			
		||||
 * <pre>{@code
 | 
			
		||||
 * {
 | 
			
		||||
 *     "type": my_mod:my_upgrade",
 | 
			
		||||
 * }
 | 
			
		||||
 * }</pre>
 | 
			
		||||
 * <p>
 | 
			
		||||
 * {@link PocketUpgradeDataProvider} provides a data provider to aid with generating these JSON files.
 | 
			
		||||
 * @see PocketUpgradeSerialiser For how to register a pocket computer upgrade.
 | 
			
		||||
 */
 | 
			
		||||
public interface IPocketUpgrade extends UpgradeBase {
 | 
			
		||||
    /**
 | 
			
		||||
     * The registry key for upgrade serialisers.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The registry key.
 | 
			
		||||
     */
 | 
			
		||||
    static ResourceKey<Registry<UpgradeSerialiser<? extends IPocketUpgrade>>> serialiserRegistryKey() {
 | 
			
		||||
        return ComputerCraftAPIService.get().pocketUpgradeRegistryId();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a peripheral for the pocket computer.
 | 
			
		||||
     * <p>
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,6 @@
 | 
			
		||||
package dan200.computercraft.api.pocket;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeDataProvider;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
 | 
			
		||||
import net.minecraft.data.DataGenerator;
 | 
			
		||||
import net.minecraft.data.PackOutput;
 | 
			
		||||
 | 
			
		||||
@@ -18,11 +17,10 @@ import java.util.function.Consumer;
 | 
			
		||||
 * {@link #addUpgrades(Consumer)} function, construct each upgrade, and pass them off to the provided consumer to
 | 
			
		||||
 * generate them.
 | 
			
		||||
 *
 | 
			
		||||
 * @see IPocketUpgrade
 | 
			
		||||
 * @see UpgradeSerialiser
 | 
			
		||||
 * @see PocketUpgradeSerialiser
 | 
			
		||||
 */
 | 
			
		||||
public abstract class PocketUpgradeDataProvider extends UpgradeDataProvider<IPocketUpgrade> {
 | 
			
		||||
public abstract class PocketUpgradeDataProvider extends UpgradeDataProvider<IPocketUpgrade, PocketUpgradeSerialiser<?>> {
 | 
			
		||||
    public PocketUpgradeDataProvider(PackOutput output) {
 | 
			
		||||
        super(output, "Pocket Computer Upgrades", "computercraft/pocket_upgrades", IPocketUpgrade.serialiserRegistryKey());
 | 
			
		||||
        super(output, "Pocket Computer Upgrades", "computercraft/pocket_upgrades", PocketUpgradeSerialiser.registryId());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,79 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2021 The CC: Tweaked Developers
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.pocket;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeBase;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.impl.ComputerCraftAPIService;
 | 
			
		||||
import dan200.computercraft.impl.upgrades.SerialiserWithCraftingItem;
 | 
			
		||||
import dan200.computercraft.impl.upgrades.SimpleSerialiser;
 | 
			
		||||
import net.minecraft.core.Registry;
 | 
			
		||||
import net.minecraft.resources.ResourceKey;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer;
 | 
			
		||||
 | 
			
		||||
import java.util.function.BiFunction;
 | 
			
		||||
import java.util.function.Function;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Reads a {@link IPocketUpgrade} from disk and reads/writes it to a network packet.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * This follows the same format as {@link dan200.computercraft.api.turtle.TurtleUpgradeSerialiser} - consult the
 | 
			
		||||
 * documentation there for more information.
 | 
			
		||||
 *
 | 
			
		||||
 * @param <T> The type of pocket computer upgrade this is responsible for serialising.
 | 
			
		||||
 * @see IPocketUpgrade
 | 
			
		||||
 * @see PocketUpgradeDataProvider
 | 
			
		||||
 */
 | 
			
		||||
public interface PocketUpgradeSerialiser<T extends IPocketUpgrade> extends UpgradeSerialiser<T> {
 | 
			
		||||
    /**
 | 
			
		||||
     * The ID for the associated registry.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The registry key.
 | 
			
		||||
     */
 | 
			
		||||
    static ResourceKey<Registry<PocketUpgradeSerialiser<?>>> registryId() {
 | 
			
		||||
        return ComputerCraftAPIService.get().pocketUpgradeRegistryId();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create an upgrade serialiser for a simple upgrade. This is similar to a {@link SimpleCraftingRecipeSerializer},
 | 
			
		||||
     * but for upgrades.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * If you might want to vary the item, it's suggested you use {@link #simpleWithCustomItem(BiFunction)} instead.
 | 
			
		||||
     *
 | 
			
		||||
     * @param factory Generate a new upgrade with a specific ID.
 | 
			
		||||
     * @param <T>     The type of the generated upgrade.
 | 
			
		||||
     * @return The serialiser for this upgrade
 | 
			
		||||
     */
 | 
			
		||||
    static <T extends IPocketUpgrade> PocketUpgradeSerialiser<T> simple(Function<ResourceLocation, T> factory) {
 | 
			
		||||
        final class Impl extends SimpleSerialiser<T> implements PocketUpgradeSerialiser<T> {
 | 
			
		||||
            private Impl(Function<ResourceLocation, T> constructor) {
 | 
			
		||||
                super(constructor);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new Impl(factory);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create an upgrade serialiser for a simple upgrade whose crafting item can be specified.
 | 
			
		||||
     *
 | 
			
		||||
     * @param factory Generate a new upgrade with a specific ID and crafting item. The returned upgrade's
 | 
			
		||||
     *                {@link UpgradeBase#getCraftingItem()} <strong>MUST</strong> equal the provided item.
 | 
			
		||||
     * @param <T>     The type of the generated upgrade.
 | 
			
		||||
     * @return The serialiser for this upgrade.
 | 
			
		||||
     * @see #simple(Function)  For upgrades whose crafting stack should not vary.
 | 
			
		||||
     */
 | 
			
		||||
    static <T extends IPocketUpgrade> PocketUpgradeSerialiser<T> simpleWithCustomItem(BiFunction<ResourceLocation, ItemStack, T> factory) {
 | 
			
		||||
        final class Impl extends SerialiserWithCraftingItem<T> implements PocketUpgradeSerialiser<T> {
 | 
			
		||||
            private Impl(BiFunction<ResourceLocation, ItemStack, T> factory) {
 | 
			
		||||
                super(factory);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new Impl(factory);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -6,12 +6,8 @@ package dan200.computercraft.api.turtle;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheral;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeBase;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.impl.ComputerCraftAPIService;
 | 
			
		||||
import net.minecraft.core.Direction;
 | 
			
		||||
import net.minecraft.core.Registry;
 | 
			
		||||
import net.minecraft.nbt.CompoundTag;
 | 
			
		||||
import net.minecraft.resources.ResourceKey;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
 | 
			
		||||
@@ -20,54 +16,15 @@ import javax.annotation.Nullable;
 | 
			
		||||
 * peripheral.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * Turtle upgrades are defined in two stages. First, one creates a {@link ITurtleUpgrade} subclass and corresponding
 | 
			
		||||
 * {@link UpgradeSerialiser} instance, which are then registered in a registry.
 | 
			
		||||
 * {@link TurtleUpgradeSerialiser} instance, which are then registered in a Forge registry.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * You then write a JSON file in your mod's {@literal data/} folder. This is then parsed when the world is loaded, and
 | 
			
		||||
 * the upgrade automatically registered. It is recommended this is done via {@linkplain TurtleUpgradeDataProvider data
 | 
			
		||||
 * generators}.
 | 
			
		||||
 * the upgrade registered internally. See the documentation in {@link TurtleUpgradeSerialiser} for details on this process
 | 
			
		||||
 * and where files should be located.
 | 
			
		||||
 *
 | 
			
		||||
 * <h2>Example</h2>
 | 
			
		||||
 * <pre>{@code
 | 
			
		||||
 * // We use Forge's DeferredRegister to register our serialiser. Fabric mods may register their serialiser directly.
 | 
			
		||||
 * static final DeferredRegister<UpgradeSerialiser<? extends ITurtleUpgrade>> SERIALISERS = DeferredRegister.create(ITurtleUpgrade.serialiserRegistryKey(), "my_mod");
 | 
			
		||||
 *
 | 
			
		||||
 * // Register a new upgrade serialiser called "my_upgrade".
 | 
			
		||||
 * public static final RegistryObject<UpgradeSerialiser<MyUpgrade>> MY_UPGRADE =
 | 
			
		||||
 *     SERIALISERS.register( "my_upgrade", () -> TurtleUpgradeSerialiser.simple( MyUpgrade::new ) );
 | 
			
		||||
 *
 | 
			
		||||
 * // Then in your constructor
 | 
			
		||||
 * SERIALISERS.register( bus );
 | 
			
		||||
 * }</pre>
 | 
			
		||||
 * <p>
 | 
			
		||||
 * We can then define a new upgrade using JSON by placing the following in
 | 
			
		||||
 * {@literal data/<my_mod>/computercraft/turtle_upgrades/<my_upgrade_id>.json}}.
 | 
			
		||||
 *
 | 
			
		||||
 * <pre>{@code
 | 
			
		||||
 * {
 | 
			
		||||
 *     "type": my_mod:my_upgrade",
 | 
			
		||||
 * }
 | 
			
		||||
 * }</pre>
 | 
			
		||||
 * <p>
 | 
			
		||||
 * {@link TurtleUpgradeDataProvider} provides a data provider to aid with generating these JSON files.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * Finally, we need to register a model for our upgrade, see
 | 
			
		||||
 * {@link dan200.computercraft.api.client.turtle.TurtleUpgradeModeller} for more information.
 | 
			
		||||
 *
 | 
			
		||||
 * <pre>{@code
 | 
			
		||||
 * // Register our model inside FMLClientSetupEvent
 | 
			
		||||
 * ComputerCraftAPIClient.registerTurtleUpgradeModeller(MY_UPGRADE.get(), TurtleUpgradeModeller.flatItem())
 | 
			
		||||
 * }</pre>
 | 
			
		||||
 * @see TurtleUpgradeSerialiser For how to register a turtle upgrade.
 | 
			
		||||
 */
 | 
			
		||||
public interface ITurtleUpgrade extends UpgradeBase {
 | 
			
		||||
    /**
 | 
			
		||||
     * The registry key for upgrade serialisers.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The registry key.
 | 
			
		||||
     */
 | 
			
		||||
    static ResourceKey<Registry<UpgradeSerialiser<? extends ITurtleUpgrade>>> serialiserRegistryKey() {
 | 
			
		||||
        return ComputerCraftAPIService.get().turtleUpgradeRegistryId();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Return whether this turtle adds a tool or a peripheral to the turtle.
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,7 @@
 | 
			
		||||
package dan200.computercraft.api.turtle;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * An enum representing the two sides of the turtle that a turtle turtle might reside.
 | 
			
		||||
 * An enum representing the two sides of the turtle that a turtle upgrade might reside.
 | 
			
		||||
 */
 | 
			
		||||
public enum TurtleSide {
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -7,9 +7,8 @@ package dan200.computercraft.api.turtle;
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI;
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftTags;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeDataProvider;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.impl.RegistryHelper;
 | 
			
		||||
import net.minecraft.core.registries.BuiltInRegistries;
 | 
			
		||||
import dan200.computercraft.impl.PlatformHelper;
 | 
			
		||||
import net.minecraft.core.registries.Registries;
 | 
			
		||||
import net.minecraft.data.DataGenerator;
 | 
			
		||||
import net.minecraft.data.PackOutput;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
@@ -30,13 +29,13 @@ import java.util.function.Consumer;
 | 
			
		||||
 * {@link #addUpgrades(Consumer)} function, construct each upgrade, and pass them off to the provided consumer to
 | 
			
		||||
 * generate them.
 | 
			
		||||
 *
 | 
			
		||||
 * @see ITurtleUpgrade
 | 
			
		||||
 * @see TurtleUpgradeSerialiser
 | 
			
		||||
 */
 | 
			
		||||
public abstract class TurtleUpgradeDataProvider extends UpgradeDataProvider<ITurtleUpgrade> {
 | 
			
		||||
public abstract class TurtleUpgradeDataProvider extends UpgradeDataProvider<ITurtleUpgrade, TurtleUpgradeSerialiser<?>> {
 | 
			
		||||
    private static final ResourceLocation TOOL_ID = new ResourceLocation(ComputerCraftAPI.MOD_ID, "tool");
 | 
			
		||||
 | 
			
		||||
    public TurtleUpgradeDataProvider(PackOutput output) {
 | 
			
		||||
        super(output, "Turtle Upgrades", "computercraft/turtle_upgrades", ITurtleUpgrade.serialiserRegistryKey());
 | 
			
		||||
        super(output, "Turtle Upgrades", "computercraft/turtle_upgrades", TurtleUpgradeSerialiser.registryId());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -58,7 +57,7 @@ public abstract class TurtleUpgradeDataProvider extends UpgradeDataProvider<ITur
 | 
			
		||||
     */
 | 
			
		||||
    public static class ToolBuilder {
 | 
			
		||||
        private final ResourceLocation id;
 | 
			
		||||
        private final UpgradeSerialiser<? extends ITurtleUpgrade> serialiser;
 | 
			
		||||
        private final TurtleUpgradeSerialiser<?> serialiser;
 | 
			
		||||
        private final Item toolItem;
 | 
			
		||||
        private @Nullable String adjective;
 | 
			
		||||
        private @Nullable Item craftingItem;
 | 
			
		||||
@@ -67,7 +66,7 @@ public abstract class TurtleUpgradeDataProvider extends UpgradeDataProvider<ITur
 | 
			
		||||
        private boolean allowEnchantments = false;
 | 
			
		||||
        private TurtleToolDurability consumeDurability = TurtleToolDurability.NEVER;
 | 
			
		||||
 | 
			
		||||
        ToolBuilder(ResourceLocation id, UpgradeSerialiser<? extends ITurtleUpgrade> serialiser, Item toolItem) {
 | 
			
		||||
        ToolBuilder(ResourceLocation id, TurtleUpgradeSerialiser<?> serialiser, Item toolItem) {
 | 
			
		||||
            this.id = id;
 | 
			
		||||
            this.serialiser = serialiser;
 | 
			
		||||
            this.toolItem = toolItem;
 | 
			
		||||
@@ -150,12 +149,12 @@ public abstract class TurtleUpgradeDataProvider extends UpgradeDataProvider<ITur
 | 
			
		||||
         *
 | 
			
		||||
         * @param add The callback given to {@link #addUpgrades(Consumer)}.
 | 
			
		||||
         */
 | 
			
		||||
        public void add(Consumer<Upgrade<UpgradeSerialiser<? extends ITurtleUpgrade>>> add) {
 | 
			
		||||
        public void add(Consumer<Upgrade<TurtleUpgradeSerialiser<?>>> add) {
 | 
			
		||||
            add.accept(new Upgrade<>(id, serialiser, s -> {
 | 
			
		||||
                s.addProperty("item", RegistryHelper.getKeyOrThrow(BuiltInRegistries.ITEM, toolItem).toString());
 | 
			
		||||
                s.addProperty("item", PlatformHelper.get().getRegistryKey(Registries.ITEM, toolItem).toString());
 | 
			
		||||
                if (adjective != null) s.addProperty("adjective", adjective);
 | 
			
		||||
                if (craftingItem != null) {
 | 
			
		||||
                    s.addProperty("craftItem", RegistryHelper.getKeyOrThrow(BuiltInRegistries.ITEM, craftingItem).toString());
 | 
			
		||||
                    s.addProperty("craftItem", PlatformHelper.get().getRegistryKey(Registries.ITEM, craftingItem).toString());
 | 
			
		||||
                }
 | 
			
		||||
                if (damageMultiplier != null) s.addProperty("damageMultiplier", damageMultiplier);
 | 
			
		||||
                if (breakable != null) s.addProperty("breakable", breakable.location().toString());
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,109 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2021 The CC: Tweaked Developers
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.turtle;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeBase;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.impl.ComputerCraftAPIService;
 | 
			
		||||
import dan200.computercraft.impl.upgrades.SerialiserWithCraftingItem;
 | 
			
		||||
import dan200.computercraft.impl.upgrades.SimpleSerialiser;
 | 
			
		||||
import net.minecraft.core.Registry;
 | 
			
		||||
import net.minecraft.resources.ResourceKey;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import net.minecraft.world.item.crafting.RecipeSerializer;
 | 
			
		||||
import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer;
 | 
			
		||||
 | 
			
		||||
import java.util.function.BiFunction;
 | 
			
		||||
import java.util.function.Function;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Reads a {@link ITurtleUpgrade} from disk and reads/writes it to a network packet.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * These should be registered in a {@link Registry} while the game is loading, much like {@link RecipeSerializer}s.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * If your turtle upgrade doesn't have any associated configurable parameters (like most upgrades), you can use
 | 
			
		||||
 * {@link #simple(Function)} or {@link #simpleWithCustomItem(BiFunction)} to create a basic upgrade serialiser.
 | 
			
		||||
 *
 | 
			
		||||
 * <h2>Example (Forge)</h2>
 | 
			
		||||
 * <pre>{@code
 | 
			
		||||
 * static final DeferredRegister<TurtleUpgradeSerialiser<?>> SERIALISERS = DeferredRegister.create( TurtleUpgradeSerialiser.TYPE, "my_mod" );
 | 
			
		||||
 *
 | 
			
		||||
 * // Register a new upgrade serialiser called "my_upgrade".
 | 
			
		||||
 * public static final RegistryObject<TurtleUpgradeSerialiser<MyUpgrade>> MY_UPGRADE =
 | 
			
		||||
 *     SERIALISERS.register( "my_upgrade", () -> TurtleUpgradeSerialiser.simple( MyUpgrade::new ) );
 | 
			
		||||
 *
 | 
			
		||||
 * // Then in your constructor
 | 
			
		||||
 * SERIALISERS.register( bus );
 | 
			
		||||
 * }</pre>
 | 
			
		||||
 * <p>
 | 
			
		||||
 * We can then define a new upgrade using JSON by placing the following in
 | 
			
		||||
 * {@literal data/<my_mod>/computercraft/turtle_upgrades/<my_upgrade_id>.json}}.
 | 
			
		||||
 *
 | 
			
		||||
 * <pre>{@code
 | 
			
		||||
 * {
 | 
			
		||||
 *     "type": my_mod:my_upgrade",
 | 
			
		||||
 * }
 | 
			
		||||
 * }</pre>
 | 
			
		||||
 * <p>
 | 
			
		||||
 * Finally, we need to register a model for our upgrade. The way to do this varies on mod loader, see
 | 
			
		||||
 * {@link dan200.computercraft.api.client.turtle.TurtleUpgradeModeller} for more information.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * {@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 dan200.computercraft.api.client.turtle.TurtleUpgradeModeller
 | 
			
		||||
 */
 | 
			
		||||
public interface TurtleUpgradeSerialiser<T extends ITurtleUpgrade> extends UpgradeSerialiser<T> {
 | 
			
		||||
    /**
 | 
			
		||||
     * The ID for the associated registry.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The registry key.
 | 
			
		||||
     */
 | 
			
		||||
    static ResourceKey<Registry<TurtleUpgradeSerialiser<?>>> registryId() {
 | 
			
		||||
        return ComputerCraftAPIService.get().turtleUpgradeRegistryId();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create an upgrade serialiser for a simple upgrade. This is similar to a {@link SimpleCraftingRecipeSerializer},
 | 
			
		||||
     * but for upgrades.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * If you might want to vary the item, it's suggested you use {@link #simpleWithCustomItem(BiFunction)} instead.
 | 
			
		||||
     *
 | 
			
		||||
     * @param factory Generate a new upgrade with a specific ID.
 | 
			
		||||
     * @param <T>     The type of the generated upgrade.
 | 
			
		||||
     * @return The serialiser for this upgrade
 | 
			
		||||
     */
 | 
			
		||||
    static <T extends ITurtleUpgrade> TurtleUpgradeSerialiser<T> simple(Function<ResourceLocation, T> factory) {
 | 
			
		||||
        final class Impl extends SimpleSerialiser<T> implements TurtleUpgradeSerialiser<T> {
 | 
			
		||||
            private Impl(Function<ResourceLocation, T> constructor) {
 | 
			
		||||
                super(constructor);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new Impl(factory);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create an upgrade serialiser for a simple upgrade whose crafting item can be specified.
 | 
			
		||||
     *
 | 
			
		||||
     * @param factory Generate a new upgrade with a specific ID and crafting item. The returned upgrade's
 | 
			
		||||
     *                {@link UpgradeBase#getCraftingItem()} <strong>MUST</strong> equal the provided item.
 | 
			
		||||
     * @param <T>     The type of the generated upgrade.
 | 
			
		||||
     * @return The serialiser for this upgrade.
 | 
			
		||||
     * @see #simple(Function)  For upgrades whose crafting stack should not vary.
 | 
			
		||||
     */
 | 
			
		||||
    static <T extends ITurtleUpgrade> TurtleUpgradeSerialiser<T> simpleWithCustomItem(BiFunction<ResourceLocation, ItemStack, T> factory) {
 | 
			
		||||
        final class Impl extends SerialiserWithCraftingItem<T> implements TurtleUpgradeSerialiser<T> {
 | 
			
		||||
            private Impl(BiFunction<ResourceLocation, ItemStack, T> factory) {
 | 
			
		||||
                super(factory);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new Impl(factory);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -9,6 +9,7 @@ import dan200.computercraft.api.pocket.IPocketUpgrade;
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleAccess;
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleSide;
 | 
			
		||||
import dan200.computercraft.impl.PlatformHelper;
 | 
			
		||||
import net.minecraft.Util;
 | 
			
		||||
import net.minecraft.nbt.CompoundTag;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
@@ -99,7 +100,7 @@ public interface UpgradeBase {
 | 
			
		||||
     * The default check requires that any non-capability NBT is exactly the same as the
 | 
			
		||||
     * crafting item, but this may be relaxed for your upgrade.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * This is based on {@code net.neoforged.common.crafting.StrictNBTIngredient}'s check.
 | 
			
		||||
     * This is based on {@code net.minecraftforge.common.crafting.StrictNBTIngredient}'s check.
 | 
			
		||||
     *
 | 
			
		||||
     * @param stack The stack to check. This is guaranteed to be non-empty and have the same item as
 | 
			
		||||
     *              {@link #getCraftingItem()}.
 | 
			
		||||
@@ -110,12 +111,12 @@ public interface UpgradeBase {
 | 
			
		||||
 | 
			
		||||
        // A more expanded form of ItemStack.areShareTagsEqual, but allowing an empty tag to be equal to a
 | 
			
		||||
        // null one.
 | 
			
		||||
        var tag = stack.getTag();
 | 
			
		||||
        var craftingTag = crafting.getTag();
 | 
			
		||||
        if (tag == craftingTag) return true;
 | 
			
		||||
        if (tag == null) return Objects.requireNonNull(craftingTag).isEmpty();
 | 
			
		||||
        if (craftingTag == null) return tag.isEmpty();
 | 
			
		||||
        return tag.equals(craftingTag);
 | 
			
		||||
        var shareTag = PlatformHelper.get().getShareTag(stack);
 | 
			
		||||
        var craftingShareTag = PlatformHelper.get().getShareTag(crafting);
 | 
			
		||||
        if (shareTag == craftingShareTag) return true;
 | 
			
		||||
        if (shareTag == null) return Objects.requireNonNull(craftingShareTag).isEmpty();
 | 
			
		||||
        if (craftingShareTag == null) return shareTag.isEmpty();
 | 
			
		||||
        return shareTag.equals(craftingShareTag);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -6,20 +6,19 @@ package dan200.computercraft.api.upgrades;
 | 
			
		||||
 | 
			
		||||
import com.google.gson.JsonObject;
 | 
			
		||||
import com.google.gson.JsonParseException;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.impl.PlatformHelper;
 | 
			
		||||
import dan200.computercraft.impl.RegistryHelper;
 | 
			
		||||
import dan200.computercraft.impl.upgrades.SerialiserWithCraftingItem;
 | 
			
		||||
import dan200.computercraft.impl.upgrades.SimpleSerialiser;
 | 
			
		||||
import net.minecraft.Util;
 | 
			
		||||
import net.minecraft.core.Registry;
 | 
			
		||||
import net.minecraft.core.registries.BuiltInRegistries;
 | 
			
		||||
import net.minecraft.core.registries.Registries;
 | 
			
		||||
import net.minecraft.data.CachedOutput;
 | 
			
		||||
import net.minecraft.data.DataProvider;
 | 
			
		||||
import net.minecraft.data.PackOutput;
 | 
			
		||||
import net.minecraft.resources.ResourceKey;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.world.item.Item;
 | 
			
		||||
import org.jetbrains.annotations.ApiStatus;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
@@ -32,31 +31,31 @@ import java.util.function.Function;
 | 
			
		||||
 * the other subclasses.
 | 
			
		||||
 *
 | 
			
		||||
 * @param <T> The base class of upgrades.
 | 
			
		||||
 * @param <R> The upgrade serialiser to register for.
 | 
			
		||||
 */
 | 
			
		||||
public abstract class UpgradeDataProvider<T extends UpgradeBase> implements DataProvider {
 | 
			
		||||
public abstract class UpgradeDataProvider<T extends UpgradeBase, R extends UpgradeSerialiser<? extends T>> implements DataProvider {
 | 
			
		||||
    private final PackOutput output;
 | 
			
		||||
    private final String name;
 | 
			
		||||
    private final String folder;
 | 
			
		||||
    private final Registry<UpgradeSerialiser<? extends T>> registry;
 | 
			
		||||
    private final ResourceKey<Registry<R>> registry;
 | 
			
		||||
 | 
			
		||||
    private @Nullable List<T> upgrades;
 | 
			
		||||
 | 
			
		||||
    @ApiStatus.Internal
 | 
			
		||||
    protected UpgradeDataProvider(PackOutput output, String name, String folder, ResourceKey<Registry<UpgradeSerialiser<? extends T>>> registry) {
 | 
			
		||||
    protected UpgradeDataProvider(PackOutput output, String name, String folder, ResourceKey<Registry<R>> registry) {
 | 
			
		||||
        this.output = output;
 | 
			
		||||
        this.name = name;
 | 
			
		||||
        this.folder = folder;
 | 
			
		||||
        this.registry = RegistryHelper.getRegistry(registry);
 | 
			
		||||
        this.registry = registry;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Register an upgrade using a {@linkplain UpgradeSerialiser#simple(Function) "simple" serialiser}.
 | 
			
		||||
     * Register an upgrade using a "simple" serialiser (e.g. {@link TurtleUpgradeSerialiser#simple(Function)}).
 | 
			
		||||
     *
 | 
			
		||||
     * @param id         The ID of the upgrade to create.
 | 
			
		||||
     * @param serialiser The simple serialiser.
 | 
			
		||||
     * @return The constructed upgrade, ready to be passed off to {@link #addUpgrades(Consumer)}'s consumer.
 | 
			
		||||
     */
 | 
			
		||||
    public final Upgrade<UpgradeSerialiser<? extends T>> simple(ResourceLocation id, UpgradeSerialiser<? extends T> serialiser) {
 | 
			
		||||
    public final Upgrade<R> simple(ResourceLocation id, R serialiser) {
 | 
			
		||||
        if (!(serialiser instanceof SimpleSerialiser)) {
 | 
			
		||||
            throw new IllegalStateException(serialiser + " must be a simple() seriaiser.");
 | 
			
		||||
        }
 | 
			
		||||
@@ -66,20 +65,20 @@ public abstract class UpgradeDataProvider<T extends UpgradeBase> implements Data
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Register an upgrade using a {@linkplain UpgradeSerialiser#simple(Function) simple serialiser}.
 | 
			
		||||
     * Register an upgrade using a "simple" serialiser (e.g. {@link TurtleUpgradeSerialiser#simple(Function)}).
 | 
			
		||||
     *
 | 
			
		||||
     * @param id         The ID of the upgrade to create.
 | 
			
		||||
     * @param serialiser The simple serialiser.
 | 
			
		||||
     * @param item       The crafting upgrade for this item.
 | 
			
		||||
     * @return The constructed upgrade, ready to be passed off to {@link #addUpgrades(Consumer)}'s consumer.
 | 
			
		||||
     */
 | 
			
		||||
    public final Upgrade<UpgradeSerialiser<? extends T>> simpleWithCustomItem(ResourceLocation id, UpgradeSerialiser<? extends T> serialiser, Item item) {
 | 
			
		||||
    public final Upgrade<R> simpleWithCustomItem(ResourceLocation id, R serialiser, Item item) {
 | 
			
		||||
        if (!(serialiser instanceof SerialiserWithCraftingItem)) {
 | 
			
		||||
            throw new IllegalStateException(serialiser + " must be a simpleWithCustomItem() serialiser.");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new Upgrade<>(id, serialiser, s ->
 | 
			
		||||
            s.addProperty("item", RegistryHelper.getKeyOrThrow(BuiltInRegistries.ITEM, item).toString())
 | 
			
		||||
            s.addProperty("item", PlatformHelper.get().getRegistryKey(Registries.ITEM, item).toString())
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -95,7 +94,7 @@ public abstract class UpgradeDataProvider<T extends UpgradeBase> implements Data
 | 
			
		||||
     *
 | 
			
		||||
     * @param addUpgrade A callback used to register an upgrade.
 | 
			
		||||
     */
 | 
			
		||||
    protected abstract void addUpgrades(Consumer<Upgrade<UpgradeSerialiser<? extends T>>> addUpgrade);
 | 
			
		||||
    protected abstract void addUpgrades(Consumer<Upgrade<R>> addUpgrade);
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public CompletableFuture<?> run(CachedOutput cache) {
 | 
			
		||||
@@ -108,7 +107,7 @@ public abstract class UpgradeDataProvider<T extends UpgradeBase> implements Data
 | 
			
		||||
            if (!seen.add(upgrade.id())) throw new IllegalStateException("Duplicate upgrade " + upgrade.id());
 | 
			
		||||
 | 
			
		||||
            var json = new JsonObject();
 | 
			
		||||
            json.addProperty("type", RegistryHelper.getKeyOrThrow(registry, upgrade.serialiser()).toString());
 | 
			
		||||
            json.addProperty("type", PlatformHelper.get().getRegistryKey(registry, upgrade.serialiser()).toString());
 | 
			
		||||
            upgrade.serialise().accept(json);
 | 
			
		||||
 | 
			
		||||
            futures.add(DataProvider.saveStable(cache, json, base.resolve(upgrade.id().getNamespace() + "/" + folder + "/" + upgrade.id().getPath() + ".json")));
 | 
			
		||||
@@ -130,9 +129,9 @@ public abstract class UpgradeDataProvider<T extends UpgradeBase> implements Data
 | 
			
		||||
        return name;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public final UpgradeSerialiser<? extends T> existingSerialiser(ResourceLocation id) {
 | 
			
		||||
        var result = registry.get(id);
 | 
			
		||||
        if (result == null) throw new IllegalArgumentException("No such serialiser " + id);
 | 
			
		||||
    public final R existingSerialiser(ResourceLocation id) {
 | 
			
		||||
        var result = PlatformHelper.get().getRegistryObject(registry, id);
 | 
			
		||||
        if (result == null) throw new IllegalArgumentException("No such serialiser " + registry);
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,40 +5,21 @@
 | 
			
		||||
package dan200.computercraft.api.upgrades;
 | 
			
		||||
 | 
			
		||||
import com.google.gson.JsonObject;
 | 
			
		||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
 | 
			
		||||
import dan200.computercraft.api.pocket.PocketUpgradeDataProvider;
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleUpgradeDataProvider;
 | 
			
		||||
import dan200.computercraft.impl.upgrades.SerialiserWithCraftingItem;
 | 
			
		||||
import dan200.computercraft.impl.upgrades.SimpleSerialiser;
 | 
			
		||||
import net.minecraft.core.Registry;
 | 
			
		||||
import dan200.computercraft.api.pocket.PocketUpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
 | 
			
		||||
import net.minecraft.network.FriendlyByteBuf;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import net.minecraft.world.item.crafting.RecipeSerializer;
 | 
			
		||||
import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer;
 | 
			
		||||
 | 
			
		||||
import java.util.function.BiFunction;
 | 
			
		||||
import java.util.function.Function;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A serialiser for {@link ITurtleUpgrade} or {@link IPocketUpgrade}s.
 | 
			
		||||
 * Base interface for upgrade serialisers. This should generally not be implemented directly, instead implementing one
 | 
			
		||||
 * of {@link TurtleUpgradeSerialiser} or {@link PocketUpgradeSerialiser}.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * These should be registered in a {@link Registry} while the game is loading, much like {@link RecipeSerializer}s.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * This interface is very similar to {@link RecipeSerializer}; each serialiser should correspond to a specific upgrade
 | 
			
		||||
 * class. Upgrades are then read from JSON files in datapacks, allowing multiple instances of the upgrade to be
 | 
			
		||||
 * registered.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * If your upgrade doesn't have any associated configurable parameters (like most upgrades), you can use
 | 
			
		||||
 * {@link #simple(Function)} or {@link #simpleWithCustomItem(BiFunction)} to create a basic upgrade serialiser.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * Upgrades may be data generated via a {@link UpgradeDataProvider} (see {@link TurtleUpgradeDataProvider} and
 | 
			
		||||
 * {@link PocketUpgradeDataProvider}).
 | 
			
		||||
 * However, it may sometimes be useful to implement this if you have some shared logic between upgrade types.
 | 
			
		||||
 *
 | 
			
		||||
 * @param <T> The upgrade that this class can serialise and deserialise.
 | 
			
		||||
 * @see ITurtleUpgrade
 | 
			
		||||
 * @see IPocketUpgrade
 | 
			
		||||
 * @see TurtleUpgradeSerialiser
 | 
			
		||||
 * @see PocketUpgradeSerialiser
 | 
			
		||||
 */
 | 
			
		||||
public interface UpgradeSerialiser<T extends UpgradeBase> {
 | 
			
		||||
    /**
 | 
			
		||||
@@ -68,30 +49,4 @@ public interface UpgradeSerialiser<T extends UpgradeBase> {
 | 
			
		||||
     */
 | 
			
		||||
    void toNetwork(FriendlyByteBuf buffer, T upgrade);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create an upgrade serialiser for a simple upgrade. This is similar to a {@link SimpleCraftingRecipeSerializer},
 | 
			
		||||
     * but for upgrades.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * If you might want to vary the item, it's suggested you use {@link #simpleWithCustomItem(BiFunction)} instead.
 | 
			
		||||
     *
 | 
			
		||||
     * @param factory Generate a new upgrade with a specific ID.
 | 
			
		||||
     * @param <T>     The type of the generated upgrade.
 | 
			
		||||
     * @return The serialiser for this upgrade
 | 
			
		||||
     */
 | 
			
		||||
    static <T extends UpgradeBase> UpgradeSerialiser<T> simple(Function<ResourceLocation, T> factory) {
 | 
			
		||||
        return new SimpleSerialiser<>(factory);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create an upgrade serialiser for a simple upgrade whose crafting item can be specified.
 | 
			
		||||
     *
 | 
			
		||||
     * @param factory Generate a new upgrade with a specific ID and crafting item. The returned upgrade's
 | 
			
		||||
     *                {@link UpgradeBase#getCraftingItem()} <strong>MUST</strong> equal the provided item.
 | 
			
		||||
     * @param <T>     The type of the generated upgrade.
 | 
			
		||||
     * @return The serialiser for this upgrade.
 | 
			
		||||
     * @see #simple(Function)  For upgrades whose crafting stack should not vary.
 | 
			
		||||
     */
 | 
			
		||||
    static <T extends UpgradeBase> UpgradeSerialiser<T> simpleWithCustomItem(BiFunction<ResourceLocation, ItemStack, T> factory) {
 | 
			
		||||
        return new SerialiserWithCraftingItem<>(factory);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -15,11 +15,10 @@ import dan200.computercraft.api.media.MediaProvider;
 | 
			
		||||
import dan200.computercraft.api.network.PacketNetwork;
 | 
			
		||||
import dan200.computercraft.api.network.wired.WiredElement;
 | 
			
		||||
import dan200.computercraft.api.network.wired.WiredNode;
 | 
			
		||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
 | 
			
		||||
import dan200.computercraft.api.pocket.PocketUpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.api.redstone.BundledRedstoneProvider;
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleRefuelHandler;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
 | 
			
		||||
import net.minecraft.core.BlockPos;
 | 
			
		||||
import net.minecraft.core.Direction;
 | 
			
		||||
import net.minecraft.core.Registry;
 | 
			
		||||
@@ -68,9 +67,9 @@ public interface ComputerCraftAPIService {
 | 
			
		||||
 | 
			
		||||
    void registerRefuelHandler(TurtleRefuelHandler handler);
 | 
			
		||||
 | 
			
		||||
    ResourceKey<Registry<UpgradeSerialiser<? extends ITurtleUpgrade>>> turtleUpgradeRegistryId();
 | 
			
		||||
    ResourceKey<Registry<TurtleUpgradeSerialiser<?>>> turtleUpgradeRegistryId();
 | 
			
		||||
 | 
			
		||||
    ResourceKey<Registry<UpgradeSerialiser<? extends IPocketUpgrade>>> pocketUpgradeRegistryId();
 | 
			
		||||
    ResourceKey<Registry<PocketUpgradeSerialiser<?>>> pocketUpgradeRegistryId();
 | 
			
		||||
 | 
			
		||||
    DetailRegistry<ItemStack> getItemStackDetailRegistry();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,11 @@ package dan200.computercraft.impl;
 | 
			
		||||
 | 
			
		||||
import com.google.gson.JsonObject;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeDataProvider;
 | 
			
		||||
import net.minecraft.core.Registry;
 | 
			
		||||
import net.minecraft.nbt.CompoundTag;
 | 
			
		||||
import net.minecraft.resources.ResourceKey;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import org.jetbrains.annotations.ApiStatus;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
@@ -27,6 +32,39 @@ public interface PlatformHelper {
 | 
			
		||||
        return instance == null ? Services.raise(PlatformHelper.class, Instance.ERROR) : instance;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the unique ID for a registered object.
 | 
			
		||||
     *
 | 
			
		||||
     * @param registry The registry to look up this object in.
 | 
			
		||||
     * @param object   The object to look up.
 | 
			
		||||
     * @param <T>      The type of object the registry stores.
 | 
			
		||||
     * @return The registered object's ID.
 | 
			
		||||
     * @throws IllegalArgumentException If the registry or object are not registered.
 | 
			
		||||
     */
 | 
			
		||||
    <T> ResourceLocation getRegistryKey(ResourceKey<Registry<T>> registry, T object);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Look up an ID in a registry, returning the registered object.
 | 
			
		||||
     *
 | 
			
		||||
     * @param registry The registry to look up this object in.
 | 
			
		||||
     * @param id       The ID to look up.
 | 
			
		||||
     * @param <T>      The type of object the registry stores.
 | 
			
		||||
     * @return The resolved registry object.
 | 
			
		||||
     * @throws IllegalArgumentException If the registry or object are not registered.
 | 
			
		||||
     */
 | 
			
		||||
    <T> T getRegistryObject(ResourceKey<Registry<T>> registry, ResourceLocation id);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the subset of an {@link ItemStack}'s {@linkplain ItemStack#getTag() tag} which is synced to the client.
 | 
			
		||||
     *
 | 
			
		||||
     * @param item The stack.
 | 
			
		||||
     * @return The item's tag.
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    default CompoundTag getShareTag(ItemStack item) {
 | 
			
		||||
        return item.getTag();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Add a resource condition which requires a mod to be loaded. This should be used by data providers such as
 | 
			
		||||
     * {@link UpgradeDataProvider}.
 | 
			
		||||
 
 | 
			
		||||
@@ -1,49 +0,0 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2023 The CC: Tweaked Developers
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.impl;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.core.Registry;
 | 
			
		||||
import net.minecraft.core.registries.BuiltInRegistries;
 | 
			
		||||
import net.minecraft.resources.ResourceKey;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import org.jetbrains.annotations.ApiStatus;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Additioanl functions for working with {@linkplain Registry registries}.
 | 
			
		||||
 */
 | 
			
		||||
@ApiStatus.Internal
 | 
			
		||||
public final class RegistryHelper {
 | 
			
		||||
    private RegistryHelper() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Find a registry from a {@link ResourceKey}, throwing if it does not exist.
 | 
			
		||||
     *
 | 
			
		||||
     * @param id  The id of the registry.
 | 
			
		||||
     * @param <T> The contents of the registry
 | 
			
		||||
     * @return The associated registry.
 | 
			
		||||
     */
 | 
			
		||||
    @SuppressWarnings("unchecked")
 | 
			
		||||
    public static <T> Registry<T> getRegistry(ResourceKey<Registry<T>> id) {
 | 
			
		||||
        var registry = (Registry<T>) BuiltInRegistries.REGISTRY.get(id.location());
 | 
			
		||||
        if (registry == null) throw new IllegalArgumentException("Unknown registry " + id);
 | 
			
		||||
        return registry;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the key of a registry entry, throwing if it is not registered.
 | 
			
		||||
     *
 | 
			
		||||
     * @param registry The registry to look up in.
 | 
			
		||||
     * @param object   The object to look up.
 | 
			
		||||
     * @param <T>      The type of this registry.
 | 
			
		||||
     * @return The ID of this object
 | 
			
		||||
     * @see Registry#getResourceKey(Object)
 | 
			
		||||
     */
 | 
			
		||||
    public static <T> ResourceLocation getKeyOrThrow(Registry<T> registry, T object) {
 | 
			
		||||
        var key = registry.getResourceKey(object);
 | 
			
		||||
        if (key.isEmpty()) throw new IllegalArgumentException(object + " was not registered in " + registry.key());
 | 
			
		||||
        return key.get().location();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -23,27 +23,27 @@ import java.util.function.BiFunction;
 | 
			
		||||
 * @param <T> The upgrade that this class can serialise and deserialise.
 | 
			
		||||
 */
 | 
			
		||||
@ApiStatus.Internal
 | 
			
		||||
public final class SerialiserWithCraftingItem<T extends UpgradeBase> implements UpgradeSerialiser<T> {
 | 
			
		||||
public abstract class SerialiserWithCraftingItem<T extends UpgradeBase> implements UpgradeSerialiser<T> {
 | 
			
		||||
    private final BiFunction<ResourceLocation, ItemStack, T> factory;
 | 
			
		||||
 | 
			
		||||
    public SerialiserWithCraftingItem(BiFunction<ResourceLocation, ItemStack, T> factory) {
 | 
			
		||||
    protected SerialiserWithCraftingItem(BiFunction<ResourceLocation, ItemStack, T> factory) {
 | 
			
		||||
        this.factory = factory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public T fromJson(ResourceLocation id, JsonObject object) {
 | 
			
		||||
    public final T fromJson(ResourceLocation id, JsonObject object) {
 | 
			
		||||
        var item = GsonHelper.getAsItem(object, "item");
 | 
			
		||||
        return factory.apply(id, new ItemStack(item));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public T fromNetwork(ResourceLocation id, FriendlyByteBuf buffer) {
 | 
			
		||||
    public final T fromNetwork(ResourceLocation id, FriendlyByteBuf buffer) {
 | 
			
		||||
        var item = buffer.readItem();
 | 
			
		||||
        return factory.apply(id, item);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void toNetwork(FriendlyByteBuf buffer, T upgrade) {
 | 
			
		||||
    public final void toNetwork(FriendlyByteBuf buffer, T upgrade) {
 | 
			
		||||
        buffer.writeItem(upgrade.getCraftingItem());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,7 @@ import java.util.function.Function;
 | 
			
		||||
 * @param <T> The upgrade that this class can serialise and deserialise.
 | 
			
		||||
 */
 | 
			
		||||
@ApiStatus.Internal
 | 
			
		||||
public final class SimpleSerialiser<T extends UpgradeBase> implements UpgradeSerialiser<T> {
 | 
			
		||||
public abstract class SimpleSerialiser<T extends UpgradeBase> implements UpgradeSerialiser<T> {
 | 
			
		||||
    private final Function<ResourceLocation, T> constructor;
 | 
			
		||||
 | 
			
		||||
    public SimpleSerialiser(Function<ResourceLocation, T> constructor) {
 | 
			
		||||
@@ -29,16 +29,16 @@ public final class SimpleSerialiser<T extends UpgradeBase> implements UpgradeSer
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public T fromJson(ResourceLocation id, JsonObject object) {
 | 
			
		||||
    public final T fromJson(ResourceLocation id, JsonObject object) {
 | 
			
		||||
        return constructor.apply(id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public T fromNetwork(ResourceLocation id, FriendlyByteBuf buffer) {
 | 
			
		||||
    public final T fromNetwork(ResourceLocation id, FriendlyByteBuf buffer) {
 | 
			
		||||
        return constructor.apply(id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void toNetwork(FriendlyByteBuf buffer, T upgrade) {
 | 
			
		||||
    public final void toNetwork(FriendlyByteBuf buffer, T upgrade) {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,12 @@ plugins {
 | 
			
		||||
    id("cc-tweaked.publishing")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sourceSets {
 | 
			
		||||
    main {
 | 
			
		||||
        resources.srcDir("src/generated/resources")
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
minecraft {
 | 
			
		||||
    accessWideners(
 | 
			
		||||
        "src/main/resources/computercraft.accesswidener",
 | 
			
		||||
@@ -36,8 +42,8 @@ dependencies {
 | 
			
		||||
    implementation(commonClasses(project(":common-api")))
 | 
			
		||||
    clientImplementation(clientClasses(project(":common-api")))
 | 
			
		||||
 | 
			
		||||
    compileOnly(libs.mixin)
 | 
			
		||||
    compileOnly(libs.bundles.externalMods.common)
 | 
			
		||||
    compileOnly(variantOf(libs.create.forge) { classifier("slim") }) { isTransitive = false }
 | 
			
		||||
    clientCompileOnly(variantOf(libs.emi) { classifier("api") })
 | 
			
		||||
 | 
			
		||||
    annotationProcessorEverywhere(libs.autoService)
 | 
			
		||||
@@ -106,3 +112,21 @@ val lintLua by tasks.registering(IlluaminateExec::class) {
 | 
			
		||||
    doFirst { if (System.getenv("GITHUB_ACTIONS") != null) println("::add-matcher::.github/matchers/illuaminate.json") }
 | 
			
		||||
    doLast { if (System.getenv("GITHUB_ACTIONS") != null) println("::remove-matcher owner=illuaminate::") }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
val runData by tasks.registering(MergeTrees::class) {
 | 
			
		||||
    output = layout.projectDirectory.dir("src/generated/resources")
 | 
			
		||||
 | 
			
		||||
    for (loader in listOf("forge", "fabric")) {
 | 
			
		||||
        mustRunAfter(":$loader:runData")
 | 
			
		||||
        source {
 | 
			
		||||
            input {
 | 
			
		||||
                from(project(":$loader").layout.buildDirectory.dir("generatedResources"))
 | 
			
		||||
                exclude(".cache")
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            output = project(":$loader").layout.projectDirectory.dir("src/generated/resources")
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
tasks.withType(GenerateModuleMetadata::class).configureEach { isEnabled = false }
 | 
			
		||||
 
 | 
			
		||||
@@ -108,7 +108,7 @@ public final class ClientHooks {
 | 
			
		||||
     */
 | 
			
		||||
    public static void addBlockDebugInfo(Consumer<String> addText) {
 | 
			
		||||
        var minecraft = Minecraft.getInstance();
 | 
			
		||||
        if (!minecraft.getDebugOverlay().showDebugScreen() || minecraft.level == null) return;
 | 
			
		||||
        if (!minecraft.options.renderDebug || minecraft.level == null) return;
 | 
			
		||||
        if (minecraft.hitResult == null || minecraft.hitResult.getType() != HitResult.Type.BLOCK) return;
 | 
			
		||||
 | 
			
		||||
        var tile = minecraft.level.getBlockEntity(((BlockHitResult) minecraft.hitResult).getBlockPos());
 | 
			
		||||
@@ -138,7 +138,7 @@ public final class ClientHooks {
 | 
			
		||||
     * @param addText A callback which adds a single line of text.
 | 
			
		||||
     */
 | 
			
		||||
    public static void addGameDebugInfo(Consumer<String> addText) {
 | 
			
		||||
        if (MonitorBlockEntityRenderer.hasRenderedThisFrame() && Minecraft.getInstance().getDebugOverlay().showDebugScreen()) {
 | 
			
		||||
        if (MonitorBlockEntityRenderer.hasRenderedThisFrame() && Minecraft.getInstance().options.renderDebug) {
 | 
			
		||||
            addText.accept("[CC:T] Monitor renderer: " + MonitorBlockEntityRenderer.currentRenderer());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,7 @@ import dan200.computercraft.api.client.turtle.RegisterTurtleUpgradeModeller;
 | 
			
		||||
import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller;
 | 
			
		||||
import dan200.computercraft.client.gui.*;
 | 
			
		||||
import dan200.computercraft.client.pocket.ClientPocketComputers;
 | 
			
		||||
import dan200.computercraft.client.render.CustomLecternRenderer;
 | 
			
		||||
import dan200.computercraft.client.render.RenderTypes;
 | 
			
		||||
import dan200.computercraft.client.render.TurtleBlockEntityRenderer;
 | 
			
		||||
import dan200.computercraft.client.render.monitor.MonitorBlockEntityRenderer;
 | 
			
		||||
@@ -25,15 +26,12 @@ import dan200.computercraft.shared.common.IColouredItem;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.ComputerState;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.ServerContext;
 | 
			
		||||
import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu;
 | 
			
		||||
import dan200.computercraft.shared.computer.inventory.ViewComputerMenu;
 | 
			
		||||
import dan200.computercraft.shared.media.items.DiskItem;
 | 
			
		||||
import dan200.computercraft.shared.media.items.TreasureDiskItem;
 | 
			
		||||
import net.minecraft.Util;
 | 
			
		||||
import net.minecraft.client.Minecraft;
 | 
			
		||||
import net.minecraft.client.color.item.ItemColor;
 | 
			
		||||
import net.minecraft.client.gui.screens.MenuScreens;
 | 
			
		||||
import net.minecraft.client.gui.screens.Screen;
 | 
			
		||||
import net.minecraft.client.gui.screens.inventory.MenuAccess;
 | 
			
		||||
import net.minecraft.client.multiplayer.ClientLevel;
 | 
			
		||||
import net.minecraft.client.renderer.ShaderInstance;
 | 
			
		||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
 | 
			
		||||
@@ -45,8 +43,6 @@ import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.server.packs.resources.PreparableReloadListener;
 | 
			
		||||
import net.minecraft.server.packs.resources.ResourceProvider;
 | 
			
		||||
import net.minecraft.world.entity.LivingEntity;
 | 
			
		||||
import net.minecraft.world.inventory.AbstractContainerMenu;
 | 
			
		||||
import net.minecraft.world.inventory.MenuType;
 | 
			
		||||
import net.minecraft.world.item.Item;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import net.minecraft.world.level.ItemLike;
 | 
			
		||||
@@ -78,6 +74,7 @@ public final class ClientRegistry {
 | 
			
		||||
        BlockEntityRenderers.register(ModRegistry.BlockEntities.MONITOR_ADVANCED.get(), MonitorBlockEntityRenderer::new);
 | 
			
		||||
        BlockEntityRenderers.register(ModRegistry.BlockEntities.TURTLE_NORMAL.get(), TurtleBlockEntityRenderer::new);
 | 
			
		||||
        BlockEntityRenderers.register(ModRegistry.BlockEntities.TURTLE_ADVANCED.get(), TurtleBlockEntityRenderer::new);
 | 
			
		||||
        BlockEntityRenderers.register(ModRegistry.BlockEntities.LECTERN.get(), CustomLecternRenderer::new);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -86,6 +83,14 @@ public final class ClientRegistry {
 | 
			
		||||
     * @param itemProperties Callback to register item properties.
 | 
			
		||||
     */
 | 
			
		||||
    public static void registerMainThread(RegisterItemProperty itemProperties) {
 | 
			
		||||
        MenuScreens.<AbstractComputerMenu, ComputerScreen<AbstractComputerMenu>>register(ModRegistry.Menus.COMPUTER.get(), ComputerScreen::new);
 | 
			
		||||
        MenuScreens.<AbstractComputerMenu, NoTermComputerScreen<AbstractComputerMenu>>register(ModRegistry.Menus.POCKET_COMPUTER_NO_TERM.get(), NoTermComputerScreen::new);
 | 
			
		||||
        MenuScreens.register(ModRegistry.Menus.TURTLE.get(), TurtleScreen::new);
 | 
			
		||||
 | 
			
		||||
        MenuScreens.register(ModRegistry.Menus.PRINTER.get(), PrinterScreen::new);
 | 
			
		||||
        MenuScreens.register(ModRegistry.Menus.DISK_DRIVE.get(), DiskDriveScreen::new);
 | 
			
		||||
        MenuScreens.register(ModRegistry.Menus.PRINTOUT.get(), PrintoutScreen::new);
 | 
			
		||||
 | 
			
		||||
        registerItemProperty(itemProperties, "state",
 | 
			
		||||
            new UnclampedPropertyFunction((stack, world, player, random) -> {
 | 
			
		||||
                var computer = ClientPocketComputers.get(stack);
 | 
			
		||||
@@ -99,23 +104,6 @@ public final class ClientRegistry {
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void registerMenuScreens(RegisterMenuScreen register) {
 | 
			
		||||
        register.<AbstractComputerMenu, ComputerScreen<AbstractComputerMenu>>register(ModRegistry.Menus.COMPUTER.get(), ComputerScreen::new);
 | 
			
		||||
        register.<AbstractComputerMenu, ComputerScreen<AbstractComputerMenu>>register(ModRegistry.Menus.POCKET_COMPUTER.get(), ComputerScreen::new);
 | 
			
		||||
        register.<AbstractComputerMenu, NoTermComputerScreen<AbstractComputerMenu>>register(ModRegistry.Menus.POCKET_COMPUTER_NO_TERM.get(), NoTermComputerScreen::new);
 | 
			
		||||
        register.register(ModRegistry.Menus.TURTLE.get(), TurtleScreen::new);
 | 
			
		||||
 | 
			
		||||
        register.register(ModRegistry.Menus.PRINTER.get(), PrinterScreen::new);
 | 
			
		||||
        register.register(ModRegistry.Menus.DISK_DRIVE.get(), DiskDriveScreen::new);
 | 
			
		||||
        register.register(ModRegistry.Menus.PRINTOUT.get(), PrintoutScreen::new);
 | 
			
		||||
 | 
			
		||||
        register.<ViewComputerMenu, ComputerScreen<ViewComputerMenu>>register(ModRegistry.Menus.VIEW_COMPUTER.get(), ComputerScreen::new);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public interface RegisterMenuScreen {
 | 
			
		||||
        <M extends AbstractContainerMenu, U extends Screen & MenuAccess<M>> void register(MenuType<? extends M> type, MenuScreens.ScreenConstructor<M, U> factory);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void registerTurtleModellers(RegisterTurtleUpgradeModeller register) {
 | 
			
		||||
        register.register(ModRegistry.TurtleSerialisers.SPEAKER.get(), TurtleUpgradeModeller.sided(
 | 
			
		||||
            new ResourceLocation(ComputerCraftAPI.MOD_ID, "block/turtle_speaker_left"),
 | 
			
		||||
 
 | 
			
		||||
@@ -2,18 +2,19 @@
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.impl.client;
 | 
			
		||||
package dan200.computercraft.client;
 | 
			
		||||
 | 
			
		||||
import com.google.auto.service.AutoService;
 | 
			
		||||
import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller;
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
 | 
			
		||||
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.client.turtle.TurtleUpgradeModellers;
 | 
			
		||||
import dan200.computercraft.impl.client.ComputerCraftAPIClientService;
 | 
			
		||||
 | 
			
		||||
@AutoService(FabricComputerCraftAPIClientService.class)
 | 
			
		||||
public final class FabricComputerCraftAPIClientImpl implements FabricComputerCraftAPIClientService {
 | 
			
		||||
@AutoService(ComputerCraftAPIClientService.class)
 | 
			
		||||
public final class ComputerCraftAPIClientImpl implements ComputerCraftAPIClientService {
 | 
			
		||||
    @Override
 | 
			
		||||
    public <T extends ITurtleUpgrade> void registerTurtleUpgradeModeller(UpgradeSerialiser<T> serialiser, TurtleUpgradeModeller<T> modeller) {
 | 
			
		||||
    public <T extends ITurtleUpgrade> void registerTurtleUpgradeModeller(TurtleUpgradeSerialiser<T> serialiser, TurtleUpgradeModeller<T> modeller) {
 | 
			
		||||
        TurtleUpgradeModellers.register(serialiser, modeller);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -127,6 +127,7 @@ public abstract class AbstractComputerScreen<T extends AbstractComputerMenu> ext
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
 | 
			
		||||
        renderBackground(graphics);
 | 
			
		||||
        super.render(graphics, mouseX, mouseY, partialTicks);
 | 
			
		||||
        renderTooltip(graphics, mouseX, mouseY);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -49,31 +49,31 @@ public final class ClientInputHandler implements InputHandler {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void keyDown(int key, boolean repeat) {
 | 
			
		||||
        ClientNetworking.sendToServer(new KeyEventServerMessage(menu, repeat ? KeyEventServerMessage.TYPE_REPEAT : KeyEventServerMessage.TYPE_DOWN, key));
 | 
			
		||||
        ClientNetworking.sendToServer(new KeyEventServerMessage(menu, repeat ? KeyEventServerMessage.Action.REPEAT : KeyEventServerMessage.Action.DOWN, key));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void keyUp(int key) {
 | 
			
		||||
        ClientNetworking.sendToServer(new KeyEventServerMessage(menu, KeyEventServerMessage.TYPE_UP, key));
 | 
			
		||||
        ClientNetworking.sendToServer(new KeyEventServerMessage(menu, KeyEventServerMessage.Action.UP, key));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void mouseClick(int button, int x, int y) {
 | 
			
		||||
        ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.TYPE_CLICK, button, x, y));
 | 
			
		||||
        ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.Action.CLICK, button, x, y));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void mouseUp(int button, int x, int y) {
 | 
			
		||||
        ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.TYPE_UP, button, x, y));
 | 
			
		||||
        ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.Action.UP, button, x, y));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void mouseDrag(int button, int x, int y) {
 | 
			
		||||
        ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.TYPE_DRAG, button, x, y));
 | 
			
		||||
        ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.Action.DRAG, button, x, y));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void mouseScroll(int direction, int x, int y) {
 | 
			
		||||
        ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.TYPE_SCROLL, direction, x, y));
 | 
			
		||||
        ClientNetworking.sendToServer(new MouseEventServerMessage(menu, MouseEventServerMessage.Action.SCROLL, direction, x, y));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -28,6 +28,7 @@ public class DiskDriveScreen extends AbstractContainerScreen<DiskDriveMenu> {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
 | 
			
		||||
        renderBackground(graphics);
 | 
			
		||||
        super.render(graphics, mouseX, mouseY, partialTicks);
 | 
			
		||||
        renderTooltip(graphics, mouseX, mouseY);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,6 @@ import net.minecraft.client.gui.GuiGraphics;
 | 
			
		||||
import net.minecraft.client.gui.components.toasts.Toast;
 | 
			
		||||
import net.minecraft.client.gui.components.toasts.ToastComponent;
 | 
			
		||||
import net.minecraft.network.chat.Component;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.util.FormattedCharSequence;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
 | 
			
		||||
@@ -19,7 +18,6 @@ import java.util.List;
 | 
			
		||||
 * A {@link Toast} implementation which displays an arbitrary message along with an optional {@link ItemStack}.
 | 
			
		||||
 */
 | 
			
		||||
public class ItemToast implements Toast {
 | 
			
		||||
    private static final ResourceLocation TEXTURE = new ResourceLocation("toast/recipe");
 | 
			
		||||
    public static final Object TRANSFER_NO_RESPONSE_TOKEN = new Object();
 | 
			
		||||
 | 
			
		||||
    private static final long DISPLAY_TIME = 7000L;
 | 
			
		||||
@@ -81,7 +79,7 @@ public class ItemToast implements Toast {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (width == 160 && message.size() <= 1) {
 | 
			
		||||
            graphics.blitSprite(TEXTURE, 0, 0, width, height());
 | 
			
		||||
            graphics.blit(TEXTURE, 0, 0, 0, 64, width, height());
 | 
			
		||||
        } else {
 | 
			
		||||
 | 
			
		||||
            var height = height();
 | 
			
		||||
@@ -111,14 +109,14 @@ public class ItemToast implements Toast {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void renderBackgroundRow(GuiGraphics graphics, int x, int u, int y, int height) {
 | 
			
		||||
        var leftOffset = u == 0 ? 20 : 5;
 | 
			
		||||
        var leftOffset = 5;
 | 
			
		||||
        var rightOffset = Math.min(60, x - leftOffset);
 | 
			
		||||
 | 
			
		||||
        graphics.blitSprite(TEXTURE, 160, 32, 0, u, 0, y, leftOffset, height);
 | 
			
		||||
        graphics.blit(TEXTURE, 0, y, 0, 32 + u, leftOffset, height);
 | 
			
		||||
        for (var k = leftOffset; k < x - rightOffset; k += 64) {
 | 
			
		||||
            graphics.blitSprite(TEXTURE, 160, 32, 32, u, k, y, Math.min(64, x - k - rightOffset), height);
 | 
			
		||||
            graphics.blit(TEXTURE, k, y, 32, 32 + u, Math.min(64, x - k - rightOffset), height);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        graphics.blitSprite(TEXTURE, 160, 32, 160 - rightOffset, u, x - rightOffset, y, rightOffset, height);
 | 
			
		||||
        graphics.blit(TEXTURE, x - rightOffset, y, 160 - rightOffset, 32 + u, rightOffset, height);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -66,9 +66,9 @@ public class NoTermComputerScreen<T extends AbstractComputerMenu> extends Screen
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) {
 | 
			
		||||
        Objects.requireNonNull(minecraft().player).getInventory().swapPaint(scrollY);
 | 
			
		||||
        return super.mouseScrolled(mouseX, mouseY, scrollX, scrollY);
 | 
			
		||||
    public boolean mouseScrolled(double pMouseX, double pMouseY, double pDelta) {
 | 
			
		||||
        Objects.requireNonNull(minecraft().player).getInventory().swapPaint(pDelta);
 | 
			
		||||
        return super.mouseScrolled(pMouseX, pMouseY, pDelta);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -86,6 +86,8 @@ public final class OptionScreen extends Screen {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
 | 
			
		||||
        renderBackground(graphics);
 | 
			
		||||
 | 
			
		||||
        // Render the actual texture.
 | 
			
		||||
        graphics.blit(BACKGROUND, x, y, 0, 0, innerWidth, PADDING);
 | 
			
		||||
        graphics.blit(BACKGROUND,
 | 
			
		||||
 
 | 
			
		||||
@@ -30,6 +30,7 @@ public class PrinterScreen extends AbstractContainerScreen<PrinterMenu> {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
 | 
			
		||||
        renderBackground(graphics);
 | 
			
		||||
        super.render(graphics, mouseX, mouseY, partialTicks);
 | 
			
		||||
        renderTooltip(graphics, mouseX, mouseY);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -6,15 +6,22 @@ package dan200.computercraft.client.gui;
 | 
			
		||||
 | 
			
		||||
import com.mojang.blaze3d.vertex.Tesselator;
 | 
			
		||||
import dan200.computercraft.core.terminal.TextBuffer;
 | 
			
		||||
import dan200.computercraft.shared.common.HeldItemMenu;
 | 
			
		||||
import dan200.computercraft.shared.ModRegistry;
 | 
			
		||||
import dan200.computercraft.shared.media.PrintoutMenu;
 | 
			
		||||
import dan200.computercraft.shared.media.items.PrintoutItem;
 | 
			
		||||
import net.minecraft.client.gui.GuiGraphics;
 | 
			
		||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
 | 
			
		||||
import net.minecraft.client.renderer.MultiBufferSource;
 | 
			
		||||
import net.minecraft.network.chat.Component;
 | 
			
		||||
import net.minecraft.world.entity.player.Inventory;
 | 
			
		||||
import net.minecraft.world.inventory.AbstractContainerMenu;
 | 
			
		||||
import net.minecraft.world.inventory.ContainerListener;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import org.lwjgl.glfw.GLFW;
 | 
			
		||||
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.client.render.PrintoutRenderer.*;
 | 
			
		||||
import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMAP;
 | 
			
		||||
 | 
			
		||||
@@ -23,40 +30,75 @@ import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMA
 | 
			
		||||
 *
 | 
			
		||||
 * @see dan200.computercraft.client.render.PrintoutRenderer
 | 
			
		||||
 */
 | 
			
		||||
public class PrintoutScreen extends AbstractContainerScreen<HeldItemMenu> {
 | 
			
		||||
    private final boolean book;
 | 
			
		||||
    private final int pages;
 | 
			
		||||
    private final TextBuffer[] text;
 | 
			
		||||
    private final TextBuffer[] colours;
 | 
			
		||||
    private int page;
 | 
			
		||||
public final class PrintoutScreen extends AbstractContainerScreen<PrintoutMenu> implements ContainerListener {
 | 
			
		||||
    private PrintoutInfo printout = PrintoutInfo.DEFAULT;
 | 
			
		||||
    private int page = 0;
 | 
			
		||||
 | 
			
		||||
    public PrintoutScreen(HeldItemMenu container, Inventory player, Component title) {
 | 
			
		||||
    public PrintoutScreen(PrintoutMenu container, Inventory player, Component title) {
 | 
			
		||||
        super(container, player, title);
 | 
			
		||||
 | 
			
		||||
        imageHeight = Y_SIZE;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        var text = PrintoutItem.getText(container.getStack());
 | 
			
		||||
        this.text = new TextBuffer[text.length];
 | 
			
		||||
        for (var i = 0; i < this.text.length; i++) this.text[i] = new TextBuffer(text[i]);
 | 
			
		||||
    private void setPrintout(ItemStack stack) {
 | 
			
		||||
        var text = PrintoutItem.getText(stack);
 | 
			
		||||
        var textBuffers = new TextBuffer[text.length];
 | 
			
		||||
        for (var i = 0; i < textBuffers.length; i++) textBuffers[i] = new TextBuffer(text[i]);
 | 
			
		||||
 | 
			
		||||
        var colours = PrintoutItem.getColours(container.getStack());
 | 
			
		||||
        this.colours = new TextBuffer[colours.length];
 | 
			
		||||
        for (var i = 0; i < this.colours.length; i++) this.colours[i] = new TextBuffer(colours[i]);
 | 
			
		||||
        var colours = PrintoutItem.getColours(stack);
 | 
			
		||||
        var colourBuffers = new TextBuffer[colours.length];
 | 
			
		||||
        for (var i = 0; i < colours.length; i++) colourBuffers[i] = new TextBuffer(colours[i]);
 | 
			
		||||
 | 
			
		||||
        page = 0;
 | 
			
		||||
        pages = Math.max(this.text.length / PrintoutItem.LINES_PER_PAGE, 1);
 | 
			
		||||
        book = ((PrintoutItem) container.getStack().getItem()).getType() == PrintoutItem.Type.BOOK;
 | 
			
		||||
        var pages = Math.max(text.length / PrintoutItem.LINES_PER_PAGE, 1);
 | 
			
		||||
        var book = stack.is(ModRegistry.Items.PRINTED_BOOK.get());
 | 
			
		||||
 | 
			
		||||
        printout = new PrintoutInfo(pages, book, textBuffers, colourBuffers);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void init() {
 | 
			
		||||
        super.init();
 | 
			
		||||
        menu.addSlotListener(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void removed() {
 | 
			
		||||
        menu.removeSlotListener(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void slotChanged(AbstractContainerMenu menu, int slot, ItemStack stack) {
 | 
			
		||||
        if (slot == 0) setPrintout(stack);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void dataChanged(AbstractContainerMenu menu, int slot, int data) {
 | 
			
		||||
        if (slot == PrintoutMenu.DATA_CURRENT_PAGE) page = data;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void setPage(int page) {
 | 
			
		||||
        this.page = page;
 | 
			
		||||
 | 
			
		||||
        var gameMode = Objects.requireNonNull(Objects.requireNonNull(minecraft).gameMode);
 | 
			
		||||
        gameMode.handleInventoryButtonClick(menu.containerId, PrintoutMenu.PAGE_BUTTON_OFFSET + page);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void previousPage() {
 | 
			
		||||
        if (page > 0) setPage(page - 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void nextPage() {
 | 
			
		||||
        if (page < printout.pages() - 1) setPage(page + 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean keyPressed(int key, int scancode, int modifiers) {
 | 
			
		||||
        if (key == GLFW.GLFW_KEY_RIGHT) {
 | 
			
		||||
            if (page < pages - 1) page++;
 | 
			
		||||
            nextPage();
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (key == GLFW.GLFW_KEY_LEFT) {
 | 
			
		||||
            if (page > 0) page--;
 | 
			
		||||
            previousPage();
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -64,17 +106,17 @@ public class PrintoutScreen extends AbstractContainerScreen<HeldItemMenu> {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean mouseScrolled(double x, double y, double deltaX, double deltaY) {
 | 
			
		||||
        if (super.mouseScrolled(x, y, deltaX, deltaY)) return true;
 | 
			
		||||
        if (deltaY < 0) {
 | 
			
		||||
    public boolean mouseScrolled(double x, double y, double delta) {
 | 
			
		||||
        if (super.mouseScrolled(x, y, delta)) return true;
 | 
			
		||||
        if (delta < 0) {
 | 
			
		||||
            // Scroll up goes to the next page
 | 
			
		||||
            if (page < pages - 1) page++;
 | 
			
		||||
            nextPage();
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (deltaY > 0) {
 | 
			
		||||
        if (delta > 0) {
 | 
			
		||||
            // Scroll down goes to the previous page
 | 
			
		||||
            if (page > 0) page--;
 | 
			
		||||
            previousPage();
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -85,22 +127,39 @@ public class PrintoutScreen extends AbstractContainerScreen<HeldItemMenu> {
 | 
			
		||||
    protected void renderBg(GuiGraphics graphics, float partialTicks, int mouseX, int mouseY) {
 | 
			
		||||
        // Draw the printout
 | 
			
		||||
        var renderer = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
 | 
			
		||||
        drawBorder(graphics.pose(), renderer, leftPos, topPos, 0, page, pages, book, FULL_BRIGHT_LIGHTMAP);
 | 
			
		||||
        drawText(graphics.pose(), renderer, leftPos + X_TEXT_MARGIN, topPos + Y_TEXT_MARGIN, PrintoutItem.LINES_PER_PAGE * page, FULL_BRIGHT_LIGHTMAP, text, colours);
 | 
			
		||||
 | 
			
		||||
        drawBorder(graphics.pose(), renderer, leftPos, topPos, 0, page, printout.pages(), printout.book(), FULL_BRIGHT_LIGHTMAP);
 | 
			
		||||
        drawText(graphics.pose(), renderer, leftPos + X_TEXT_MARGIN, topPos + Y_TEXT_MARGIN, PrintoutItem.LINES_PER_PAGE * page, FULL_BRIGHT_LIGHTMAP, printout.text(), printout.colour());
 | 
			
		||||
        renderer.endBatch();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void renderBackground(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
 | 
			
		||||
    public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
 | 
			
		||||
        // We must take the background further back in order to not overlap with our printed pages.
 | 
			
		||||
        graphics.pose().pushPose();
 | 
			
		||||
        graphics.pose().translate(0, 0, -1);
 | 
			
		||||
        super.renderBackground(graphics, mouseX, mouseY, partialTicks);
 | 
			
		||||
        renderBackground(graphics);
 | 
			
		||||
        graphics.pose().popPose();
 | 
			
		||||
 | 
			
		||||
        super.render(graphics, mouseX, mouseY, partialTicks);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void renderLabels(GuiGraphics graphics, int mouseX, int mouseY) {
 | 
			
		||||
        // Skip rendering labels.
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    record PrintoutInfo(int pages, boolean book, TextBuffer[] text, TextBuffer[] colour) {
 | 
			
		||||
        public static final PrintoutInfo DEFAULT;
 | 
			
		||||
 | 
			
		||||
        static {
 | 
			
		||||
            var textLines = new TextBuffer[PrintoutItem.LINES_PER_PAGE];
 | 
			
		||||
            Arrays.fill(textLines, new TextBuffer(" ".repeat(PrintoutItem.LINE_MAX_LENGTH)));
 | 
			
		||||
 | 
			
		||||
            var colourLines = new TextBuffer[PrintoutItem.LINES_PER_PAGE];
 | 
			
		||||
            Arrays.fill(colourLines, new TextBuffer("f".repeat(PrintoutItem.LINE_MAX_LENGTH)));
 | 
			
		||||
 | 
			
		||||
            DEFAULT = new PrintoutInfo(1, false, textLines, colourLines);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -43,10 +43,6 @@ public class DynamicImageButton extends Button {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
 | 
			
		||||
        var message = this.message.get();
 | 
			
		||||
        setMessage(message.message());
 | 
			
		||||
        setTooltip(message.tooltip());
 | 
			
		||||
 | 
			
		||||
        var texture = this.texture.get(isHoveredOrFocused());
 | 
			
		||||
 | 
			
		||||
        RenderSystem.disableDepthTest();
 | 
			
		||||
@@ -54,6 +50,14 @@ public class DynamicImageButton extends Button {
 | 
			
		||||
        RenderSystem.enableDepthTest();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
 | 
			
		||||
        var message = this.message.get();
 | 
			
		||||
        setMessage(message.message());
 | 
			
		||||
        setTooltip(message.tooltip());
 | 
			
		||||
        super.render(graphics, mouseX, mouseY, partialTicks);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public record HintedMessage(Component message, Tooltip tooltip) {
 | 
			
		||||
        public HintedMessage(Component message, @Nullable Component hint) {
 | 
			
		||||
            this(
 | 
			
		||||
 
 | 
			
		||||
@@ -195,16 +195,16 @@ public class TerminalWidget extends AbstractWidget {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean mouseScrolled(double mouseX, double mouseY, double deltaX, double deltaY) {
 | 
			
		||||
    public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
 | 
			
		||||
        if (!inTermRegion(mouseX, mouseY)) return false;
 | 
			
		||||
        if (!hasMouseSupport() || deltaY == 0) return false;
 | 
			
		||||
        if (!hasMouseSupport() || delta == 0) return false;
 | 
			
		||||
 | 
			
		||||
        var charX = (int) ((mouseX - innerX) / FONT_WIDTH);
 | 
			
		||||
        var charY = (int) ((mouseY - innerY) / FONT_HEIGHT);
 | 
			
		||||
        charX = Math.min(Math.max(charX, 0), terminal.getWidth() - 1);
 | 
			
		||||
        charY = Math.min(Math.max(charY, 0), terminal.getHeight() - 1);
 | 
			
		||||
 | 
			
		||||
        computer.mouseScroll(deltaY < 0 ? 1 : -1, charX + 1, charY + 1);
 | 
			
		||||
        computer.mouseScroll(delta < 0 ? 1 : -1, charX + 1, charY + 1);
 | 
			
		||||
 | 
			
		||||
        lastMouseX = charX;
 | 
			
		||||
        lastMouseY = charY;
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.shared.integration.jei;
 | 
			
		||||
package dan200.computercraft.client.integration.jei;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleSide;
 | 
			
		||||
@@ -60,7 +60,7 @@ public class JEIComputerCraft implements IModPlugin {
 | 
			
		||||
        // Hide all upgrade recipes
 | 
			
		||||
        var category = registry.createRecipeLookup(RecipeTypes.CRAFTING);
 | 
			
		||||
        category.get().forEach(wrapper -> {
 | 
			
		||||
            if (RecipeModHelpers.shouldRemoveRecipe(wrapper.id())) {
 | 
			
		||||
            if (RecipeModHelpers.shouldRemoveRecipe(wrapper.getId())) {
 | 
			
		||||
                registry.hideRecipes(RecipeTypes.CRAFTING, List.of(wrapper));
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
@@ -2,9 +2,8 @@
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.shared.integration.jei;
 | 
			
		||||
package dan200.computercraft.client.integration.jei;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI;
 | 
			
		||||
import dan200.computercraft.shared.integration.UpgradeRecipeGenerator;
 | 
			
		||||
import dan200.computercraft.shared.pocket.items.PocketComputerItem;
 | 
			
		||||
import dan200.computercraft.shared.turtle.items.TurtleItem;
 | 
			
		||||
@@ -13,16 +12,13 @@ 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.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import net.minecraft.world.item.crafting.CraftingRecipe;
 | 
			
		||||
import net.minecraft.world.item.crafting.RecipeHolder;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
class RecipeResolver implements IRecipeManagerPlugin {
 | 
			
		||||
    private static final ResourceLocation RECIPE_ID = new ResourceLocation(ComputerCraftAPI.MOD_ID, "upgrade");
 | 
			
		||||
    private final UpgradeRecipeGenerator<RecipeHolder<CraftingRecipe>> resolver = new UpgradeRecipeGenerator<>(x -> new RecipeHolder<>(RECIPE_ID, x));
 | 
			
		||||
    private final UpgradeRecipeGenerator<CraftingRecipe> resolver = new UpgradeRecipeGenerator<>(x -> x);
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public <V> List<RecipeType<?>> getRecipeTypes(IFocus<V> focus) {
 | 
			
		||||
@@ -48,8 +44,8 @@ class RecipeResolver implements IRecipeManagerPlugin {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return switch (focus.getRole()) {
 | 
			
		||||
            case INPUT -> cast(RecipeTypes.CRAFTING, resolver.findRecipesWithInput(stack));
 | 
			
		||||
            case OUTPUT -> cast(RecipeTypes.CRAFTING, resolver.findRecipesWithOutput(stack));
 | 
			
		||||
            case INPUT -> cast(resolver.findRecipesWithInput(stack));
 | 
			
		||||
            case OUTPUT -> cast(resolver.findRecipesWithOutput(stack));
 | 
			
		||||
            default -> List.of();
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
@@ -60,7 +56,7 @@ class RecipeResolver implements IRecipeManagerPlugin {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @SuppressWarnings({ "unchecked", "rawtypes" })
 | 
			
		||||
    private static <T, U> List<T> cast(RecipeType<U> ignoredType, List<U> from) {
 | 
			
		||||
    private static <T, U> List<T> cast(List<U> from) {
 | 
			
		||||
        return (List) from;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,117 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2024 The CC: Tweaked Developers
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.client.model;
 | 
			
		||||
 | 
			
		||||
import com.mojang.blaze3d.vertex.PoseStack;
 | 
			
		||||
import com.mojang.blaze3d.vertex.VertexConsumer;
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI;
 | 
			
		||||
import dan200.computercraft.client.render.CustomLecternRenderer;
 | 
			
		||||
import dan200.computercraft.shared.media.items.PrintoutItem;
 | 
			
		||||
import net.minecraft.client.model.geom.ModelPart;
 | 
			
		||||
import net.minecraft.client.model.geom.PartPose;
 | 
			
		||||
import net.minecraft.client.model.geom.builders.CubeListBuilder;
 | 
			
		||||
import net.minecraft.client.model.geom.builders.MeshDefinition;
 | 
			
		||||
import net.minecraft.client.resources.model.Material;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.world.inventory.InventoryMenu;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A model for {@linkplain PrintoutItem printouts} placed on a lectern.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * This provides two models, {@linkplain #renderPages(PoseStack, VertexConsumer, int, int, int) one for a variable
 | 
			
		||||
 * number of pages}, and {@linkplain #renderBook(PoseStack, VertexConsumer, int, int) one for books}.
 | 
			
		||||
 *
 | 
			
		||||
 * @see CustomLecternRenderer
 | 
			
		||||
 */
 | 
			
		||||
public class LecternPrintoutModel {
 | 
			
		||||
    public static final ResourceLocation TEXTURE = new ResourceLocation(ComputerCraftAPI.MOD_ID, "entity/printout");
 | 
			
		||||
    public static final Material MATERIAL = new Material(InventoryMenu.BLOCK_ATLAS, TEXTURE);
 | 
			
		||||
 | 
			
		||||
    private static final int TEXTURE_WIDTH = 32;
 | 
			
		||||
    private static final int TEXTURE_HEIGHT = 32;
 | 
			
		||||
 | 
			
		||||
    private static final String PAGE_1 = "page_1";
 | 
			
		||||
    private static final String PAGE_2 = "page_2";
 | 
			
		||||
    private static final String PAGE_3 = "page_3";
 | 
			
		||||
    private static final List<String> PAGES = List.of(PAGE_1, PAGE_2, PAGE_3);
 | 
			
		||||
 | 
			
		||||
    private final ModelPart pagesRoot;
 | 
			
		||||
    private final ModelPart bookRoot;
 | 
			
		||||
    private final ModelPart[] pages;
 | 
			
		||||
 | 
			
		||||
    public LecternPrintoutModel() {
 | 
			
		||||
        pagesRoot = buildPages();
 | 
			
		||||
        bookRoot = buildBook();
 | 
			
		||||
        pages = PAGES.stream().map(pagesRoot::getChild).toArray(ModelPart[]::new);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static ModelPart buildPages() {
 | 
			
		||||
        var mesh = new MeshDefinition();
 | 
			
		||||
        var parts = mesh.getRoot();
 | 
			
		||||
        parts.addOrReplaceChild(
 | 
			
		||||
            PAGE_1,
 | 
			
		||||
            CubeListBuilder.create().texOffs(0, 0).addBox(-0.005f, -4.0f, -2.5f, 1f, 8.0f, 5.0f),
 | 
			
		||||
            PartPose.ZERO
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        parts.addOrReplaceChild(
 | 
			
		||||
            PAGE_2,
 | 
			
		||||
            CubeListBuilder.create().texOffs(12, 0).addBox(-0.005f, -4.0f, -2.5f, 1f, 8.0f, 5.0f),
 | 
			
		||||
            PartPose.offsetAndRotation(-0.125f, 0, 1.5f, (float) Math.PI * (1f / 16), 0, 0)
 | 
			
		||||
        );
 | 
			
		||||
        parts.addOrReplaceChild(
 | 
			
		||||
            PAGE_3,
 | 
			
		||||
            CubeListBuilder.create().texOffs(12, 0).addBox(-0.005f, -4.0f, -2.5f, 1f, 8.0f, 5.0f),
 | 
			
		||||
            PartPose.offsetAndRotation(-0.25f, 0, -1.5f, (float) -Math.PI * (2f / 16), 0, 0)
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        return mesh.getRoot().bake(TEXTURE_WIDTH, TEXTURE_HEIGHT);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static ModelPart buildBook() {
 | 
			
		||||
        var mesh = new MeshDefinition();
 | 
			
		||||
        var parts = mesh.getRoot();
 | 
			
		||||
 | 
			
		||||
        parts.addOrReplaceChild(
 | 
			
		||||
            "spine",
 | 
			
		||||
            CubeListBuilder.create().texOffs(12, 15).addBox(-0.005f, -5.0f, -0.5f, 0, 10, 1.0f),
 | 
			
		||||
            PartPose.ZERO
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        var angle = (float) Math.toRadians(5);
 | 
			
		||||
        parts.addOrReplaceChild(
 | 
			
		||||
            "left",
 | 
			
		||||
            CubeListBuilder.create()
 | 
			
		||||
                .texOffs(0, 10).addBox(0, -5.0f, -6.0f, 0, 10, 6.0f)
 | 
			
		||||
                .texOffs(0, 0).addBox(0.005f, -4.0f, -5.0f, 1.0f, 8.0f, 5.0f),
 | 
			
		||||
            PartPose.offsetAndRotation(-0.005f, 0, -0.5f, 0, -angle, 0)
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        parts.addOrReplaceChild(
 | 
			
		||||
            "right",
 | 
			
		||||
            CubeListBuilder.create()
 | 
			
		||||
                .texOffs(14, 10).addBox(0, -5.0f, 0, 0, 10, 6.0f)
 | 
			
		||||
                .texOffs(0, 0).addBox(0.005f, -4.0f, 0, 1.0f, 8.0f, 5.0f),
 | 
			
		||||
            PartPose.offsetAndRotation(-0.005f, 0, 0.5f, 0, angle, 0)
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        return mesh.getRoot().bake(TEXTURE_WIDTH, TEXTURE_HEIGHT);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void renderBook(PoseStack poseStack, VertexConsumer buffer, int packedLight, int packedOverlay) {
 | 
			
		||||
        bookRoot.render(poseStack, buffer, packedLight, packedOverlay, 1, 1, 1, 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void renderPages(PoseStack poseStack, VertexConsumer buffer, int packedLight, int packedOverlay, int pageCount) {
 | 
			
		||||
        if (pageCount > pages.length) pageCount = pages.length;
 | 
			
		||||
        var i = 0;
 | 
			
		||||
        for (; i < pageCount; i++) pages[i].visible = true;
 | 
			
		||||
        for (; i < pages.length; i++) pages[i].visible = false;
 | 
			
		||||
 | 
			
		||||
        pagesRoot.render(poseStack, buffer, packedLight, packedOverlay, 1, 1, 1, 1);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -49,7 +49,7 @@ public final class ClientNetworkContextImpl implements ClientNetworkContext {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void handleMonitorData(BlockPos pos, TerminalState terminal) {
 | 
			
		||||
    public void handleMonitorData(BlockPos pos, @Nullable TerminalState terminal) {
 | 
			
		||||
        var player = Minecraft.getInstance().player;
 | 
			
		||||
        if (player == null) return;
 | 
			
		||||
 | 
			
		||||
@@ -67,7 +67,7 @@ public final class ClientNetworkContextImpl implements ClientNetworkContext {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void handlePocketComputerData(UUID instanceId, ComputerState state, int lightState, TerminalState terminal) {
 | 
			
		||||
    public void handlePocketComputerData(UUID instanceId, ComputerState state, int lightState, @Nullable TerminalState terminal) {
 | 
			
		||||
        ClientPocketComputers.setState(instanceId, state, lightState, terminal);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,7 @@ import net.minecraft.client.renderer.MultiBufferSource;
 | 
			
		||||
import net.minecraft.client.resources.model.BakedModel;
 | 
			
		||||
import net.minecraft.core.BlockPos;
 | 
			
		||||
import net.minecraft.network.protocol.Packet;
 | 
			
		||||
import net.minecraft.network.protocol.common.ServerCommonPacketListener;
 | 
			
		||||
import net.minecraft.network.protocol.game.ServerGamePacketListener;
 | 
			
		||||
import net.minecraft.sounds.SoundEvent;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
@@ -27,7 +27,7 @@ public interface ClientPlatformHelper extends dan200.computercraft.impl.client.C
 | 
			
		||||
     * @param message The messsge to convert.
 | 
			
		||||
     * @return The converted message.
 | 
			
		||||
     */
 | 
			
		||||
    Packet<ServerCommonPacketListener> createPacket(NetworkMessage<ServerNetworkContext> message);
 | 
			
		||||
    Packet<ServerGamePacketListener> createPacket(NetworkMessage<ServerNetworkContext> message);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Render a {@link BakedModel}, using any loader-specific hooks.
 | 
			
		||||
 
 | 
			
		||||
@@ -43,7 +43,7 @@ public final class ClientPocketComputers {
 | 
			
		||||
     * @param lightColour  The current colour of the modem light.
 | 
			
		||||
     * @param terminalData The current terminal contents.
 | 
			
		||||
     */
 | 
			
		||||
    public static void setState(UUID instanceId, ComputerState state, int lightColour, TerminalState terminalData) {
 | 
			
		||||
    public static void setState(UUID instanceId, ComputerState state, int lightColour, @Nullable TerminalState terminalData) {
 | 
			
		||||
        var computer = instances.get(instanceId);
 | 
			
		||||
        if (computer == null) {
 | 
			
		||||
            instances.put(instanceId, new PocketComputerData(state, lightColour, terminalData));
 | 
			
		||||
 
 | 
			
		||||
@@ -26,10 +26,10 @@ public final class PocketComputerData {
 | 
			
		||||
    private ComputerState state;
 | 
			
		||||
    private int lightColour;
 | 
			
		||||
 | 
			
		||||
    PocketComputerData(ComputerState state, int lightColour, TerminalState terminalData) {
 | 
			
		||||
    PocketComputerData(ComputerState state, int lightColour, @Nullable TerminalState terminalData) {
 | 
			
		||||
        this.state = state;
 | 
			
		||||
        this.lightColour = lightColour;
 | 
			
		||||
        if (terminalData.hasTerminal()) terminal = terminalData.create();
 | 
			
		||||
        if (terminalData != null) terminal = terminalData.create();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getLightState() {
 | 
			
		||||
@@ -44,11 +44,11 @@ public final class PocketComputerData {
 | 
			
		||||
        return state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void setState(ComputerState state, int lightColour, TerminalState terminalData) {
 | 
			
		||||
    void setState(ComputerState state, int lightColour, @Nullable TerminalState terminalData) {
 | 
			
		||||
        this.state = state;
 | 
			
		||||
        this.lightColour = lightColour;
 | 
			
		||||
 | 
			
		||||
        if (terminalData.hasTerminal()) {
 | 
			
		||||
        if (terminalData != null) {
 | 
			
		||||
            if (terminal == null) {
 | 
			
		||||
                terminal = terminalData.create();
 | 
			
		||||
            } else {
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,51 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2024 The CC: Tweaked Developers
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: MPL-2.0
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.client.render;
 | 
			
		||||
 | 
			
		||||
import com.mojang.blaze3d.vertex.PoseStack;
 | 
			
		||||
import com.mojang.math.Axis;
 | 
			
		||||
import dan200.computercraft.client.model.LecternPrintoutModel;
 | 
			
		||||
import dan200.computercraft.shared.lectern.CustomLecternBlockEntity;
 | 
			
		||||
import dan200.computercraft.shared.media.items.PrintoutItem;
 | 
			
		||||
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.client.renderer.blockentity.LecternRenderer;
 | 
			
		||||
import net.minecraft.world.level.block.LecternBlock;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A block entity renderer for our {@linkplain CustomLecternBlockEntity lectern}.
 | 
			
		||||
 * <p>
 | 
			
		||||
 * This largely follows {@link LecternRenderer}, but with support for multiple types of item.
 | 
			
		||||
 */
 | 
			
		||||
public class CustomLecternRenderer implements BlockEntityRenderer<CustomLecternBlockEntity> {
 | 
			
		||||
    private final LecternPrintoutModel printoutModel;
 | 
			
		||||
 | 
			
		||||
    public CustomLecternRenderer(BlockEntityRendererProvider.Context context) {
 | 
			
		||||
        printoutModel = new LecternPrintoutModel();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void render(CustomLecternBlockEntity lectern, float partialTick, PoseStack poseStack, MultiBufferSource buffer, int packedLight, int packedOverlay) {
 | 
			
		||||
        poseStack.pushPose();
 | 
			
		||||
        poseStack.translate(0.5f, 1.0625f, 0.5f);
 | 
			
		||||
        poseStack.mulPose(Axis.YP.rotationDegrees(-lectern.getBlockState().getValue(LecternBlock.FACING).getClockWise().toYRot()));
 | 
			
		||||
        poseStack.mulPose(Axis.ZP.rotationDegrees(67.5f));
 | 
			
		||||
        poseStack.translate(0, -0.125f, 0);
 | 
			
		||||
 | 
			
		||||
        var item = lectern.getItem();
 | 
			
		||||
        if (item.getItem() instanceof PrintoutItem printout) {
 | 
			
		||||
            var vertexConsumer = LecternPrintoutModel.MATERIAL.buffer(buffer, RenderType::entitySolid);
 | 
			
		||||
            if (printout.getType() == PrintoutItem.Type.BOOK) {
 | 
			
		||||
                printoutModel.renderBook(poseStack, vertexConsumer, packedLight, packedOverlay);
 | 
			
		||||
            } else {
 | 
			
		||||
                printoutModel.renderPages(poseStack, vertexConsumer, packedLight, packedOverlay, PrintoutItem.getPageCount(item));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        poseStack.popPose();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -125,10 +125,10 @@ public class SpriteRenderer {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static float u(TextureAtlasSprite sprite, int x, int width) {
 | 
			
		||||
        return sprite.getU((float) x / width);
 | 
			
		||||
        return sprite.getU((double) x / width * 16);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static float v(TextureAtlasSprite sprite, int y, int height) {
 | 
			
		||||
        return sprite.getV((float) y / height);
 | 
			
		||||
        return sprite.getV((double) y / height * 16);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,6 @@ import com.mojang.blaze3d.platform.MemoryTracker;
 | 
			
		||||
import com.mojang.blaze3d.systems.RenderSystem;
 | 
			
		||||
import com.mojang.blaze3d.vertex.*;
 | 
			
		||||
import com.mojang.math.Axis;
 | 
			
		||||
import dan200.computercraft.annotations.ForgeOverride;
 | 
			
		||||
import dan200.computercraft.client.FrameInfo;
 | 
			
		||||
import dan200.computercraft.client.integration.ShaderMod;
 | 
			
		||||
import dan200.computercraft.client.render.RenderTypes;
 | 
			
		||||
@@ -26,7 +25,6 @@ import dan200.computercraft.shared.util.DirectionUtil;
 | 
			
		||||
import net.minecraft.client.renderer.MultiBufferSource;
 | 
			
		||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
 | 
			
		||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
 | 
			
		||||
import net.minecraft.world.phys.AABB;
 | 
			
		||||
import org.joml.Matrix3f;
 | 
			
		||||
import org.joml.Matrix4f;
 | 
			
		||||
import org.lwjgl.opengl.GL11;
 | 
			
		||||
@@ -257,11 +255,6 @@ public class MonitorBlockEntityRenderer implements BlockEntityRenderer<MonitorBl
 | 
			
		||||
        return Config.monitorDistance;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @ForgeOverride
 | 
			
		||||
    public AABB getRenderBoundingBox(MonitorBlockEntity monitor) {
 | 
			
		||||
        return monitor.getRenderBoundingBox();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if any monitors were rendered this frame.
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,6 @@ 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.nbt.CompoundTag;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
 | 
			
		||||
@@ -41,7 +40,7 @@ public class TurtleModemModeller implements TurtleUpgradeModeller<TurtleModem> {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public TransformedModel getModel(TurtleModem upgrade, @Nullable ITurtleAccess turtle, TurtleSide side, CompoundTag data) {
 | 
			
		||||
    public TransformedModel getModel(TurtleModem upgrade, @Nullable ITurtleAccess turtle, TurtleSide side) {
 | 
			
		||||
        var active = false;
 | 
			
		||||
        if (turtle != null) {
 | 
			
		||||
            var turtleNBT = turtle.getUpgradeNBTData(side);
 | 
			
		||||
 
 | 
			
		||||
@@ -10,13 +10,15 @@ 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.upgrades.UpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.impl.RegistryHelper;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
 | 
			
		||||
import dan200.computercraft.impl.PlatformHelper;
 | 
			
		||||
import dan200.computercraft.impl.TurtleUpgrades;
 | 
			
		||||
import dan200.computercraft.impl.UpgradeManager;
 | 
			
		||||
import net.minecraft.client.Minecraft;
 | 
			
		||||
import net.minecraft.nbt.CompoundTag;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import org.slf4j.Logger;
 | 
			
		||||
import org.slf4j.LoggerFactory;
 | 
			
		||||
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.WeakHashMap;
 | 
			
		||||
@@ -27,10 +29,12 @@ import java.util.stream.Stream;
 | 
			
		||||
 * A registry of {@link TurtleUpgradeModeller}s.
 | 
			
		||||
 */
 | 
			
		||||
public final class TurtleUpgradeModellers {
 | 
			
		||||
    private static final TurtleUpgradeModeller<ITurtleUpgrade> NULL_TURTLE_MODELLER = (upgrade, turtle, side, data) ->
 | 
			
		||||
    private static final Logger LOG = LoggerFactory.getLogger(TurtleUpgradeModellers.class);
 | 
			
		||||
 | 
			
		||||
    private static final TurtleUpgradeModeller<ITurtleUpgrade> NULL_TURTLE_MODELLER = (upgrade, turtle, side) ->
 | 
			
		||||
        new TransformedModel(Minecraft.getInstance().getModelManager().getMissingModel(), Transformation.identity());
 | 
			
		||||
 | 
			
		||||
    private static final Map<UpgradeSerialiser<? extends ITurtleUpgrade>, TurtleUpgradeModeller<?>> turtleModels = new ConcurrentHashMap<>();
 | 
			
		||||
    private static final Map<TurtleUpgradeSerialiser<?>, TurtleUpgradeModeller<?>> turtleModels = new ConcurrentHashMap<>();
 | 
			
		||||
    private static volatile boolean fetchedModels;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -44,12 +48,15 @@ public final class TurtleUpgradeModellers {
 | 
			
		||||
    private TurtleUpgradeModellers() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static <T extends ITurtleUpgrade> void register(UpgradeSerialiser<T> serialiser, TurtleUpgradeModeller<T> modeller) {
 | 
			
		||||
    public static <T extends ITurtleUpgrade> void register(TurtleUpgradeSerialiser<T> serialiser, TurtleUpgradeModeller<T> modeller) {
 | 
			
		||||
        if (fetchedModels) {
 | 
			
		||||
            throw new IllegalStateException(String.format(
 | 
			
		||||
                "Turtle upgrade serialiser %s must be registered before models are baked.",
 | 
			
		||||
                RegistryHelper.getKeyOrThrow(RegistryHelper.getRegistry(ITurtleUpgrade.serialiserRegistryKey()), serialiser)
 | 
			
		||||
            ));
 | 
			
		||||
            // TODO(1.20.4): Replace with an error.
 | 
			
		||||
            LOG.warn(
 | 
			
		||||
                "Turtle upgrade serialiser {} was registered too late, its models may not be loaded correctly. If you are " +
 | 
			
		||||
                    "the mod author, you may be using a deprecated API - see https://github.com/cc-tweaked/CC-Tweaked/pull/1684 " +
 | 
			
		||||
                    "for further information.",
 | 
			
		||||
                PlatformHelper.get().getRegistryKey(TurtleUpgradeSerialiser.registryId(), serialiser)
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (turtleModels.putIfAbsent(serialiser, modeller) != null) {
 | 
			
		||||
@@ -60,13 +67,13 @@ public final class TurtleUpgradeModellers {
 | 
			
		||||
    public static TransformedModel getModel(ITurtleUpgrade upgrade, ITurtleAccess access, TurtleSide side) {
 | 
			
		||||
        @SuppressWarnings("unchecked")
 | 
			
		||||
        var modeller = (TurtleUpgradeModeller<ITurtleUpgrade>) modelCache.computeIfAbsent(upgrade, TurtleUpgradeModellers::getModeller);
 | 
			
		||||
        return modeller.getModel(upgrade, access, side, access.getUpgradeNBTData(side));
 | 
			
		||||
        return modeller.getModel(upgrade, access, side);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static TransformedModel getModel(ITurtleUpgrade upgrade, CompoundTag data, TurtleSide side) {
 | 
			
		||||
        @SuppressWarnings("unchecked")
 | 
			
		||||
        var modeller = (TurtleUpgradeModeller<ITurtleUpgrade>) modelCache.computeIfAbsent(upgrade, TurtleUpgradeModellers::getModeller);
 | 
			
		||||
        return modeller.getModel(upgrade, null, side, data);
 | 
			
		||||
        return modeller.getModel(upgrade, data, side);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static TurtleUpgradeModeller<?> getModeller(ITurtleUpgrade upgradeA) {
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@
 | 
			
		||||
package dan200.computercraft.data.client;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.client.gui.GuiSprites;
 | 
			
		||||
import dan200.computercraft.client.model.LecternPrintoutModel;
 | 
			
		||||
import dan200.computercraft.data.DataProviders;
 | 
			
		||||
import dan200.computercraft.shared.turtle.inventory.UpgradeSlot;
 | 
			
		||||
import net.minecraft.client.renderer.texture.atlas.SpriteSource;
 | 
			
		||||
@@ -30,7 +31,8 @@ public final class ClientDataProviders {
 | 
			
		||||
        generator.addFromCodec("Block atlases", PackType.CLIENT_RESOURCES, "atlases", SpriteSources.FILE_CODEC, out -> {
 | 
			
		||||
            out.accept(new ResourceLocation("blocks"), List.of(
 | 
			
		||||
                new SingleFile(UpgradeSlot.LEFT_UPGRADE, Optional.empty()),
 | 
			
		||||
                new SingleFile(UpgradeSlot.RIGHT_UPGRADE, Optional.empty())
 | 
			
		||||
                new SingleFile(UpgradeSlot.RIGHT_UPGRADE, Optional.empty()),
 | 
			
		||||
                new SingleFile(LecternPrintoutModel.TEXTURE, Optional.empty())
 | 
			
		||||
            ));
 | 
			
		||||
            out.accept(GuiSprites.SPRITE_SHEET, Stream.of(
 | 
			
		||||
                // Buttons
 | 
			
		||||
 
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user