mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-11-03 23:22:59 +00:00 
			
		
		
		
	Compare commits
	
		
			148 Commits
		
	
	
		
			v1.96.1-be
			...
			v1.17.1-1.
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					c158c4babb | ||
| 
						 | 
					47e7fc25b3 | ||
| 
						 | 
					ef171c2e22 | ||
| 
						 | 
					9ef4601472 | ||
| 
						 | 
					bfbd157ffa | ||
| 
						 | 
					222197175b | ||
| 
						 | 
					767a919ad5 | ||
| 
						 | 
					6982841f6c | ||
| 
						 | 
					05fbf0eb5b | ||
| 
						 | 
					8737d4f6a8 | ||
| 
						 | 
					26f0ad9fa7 | ||
| 
						 | 
					4e37e8fac5 | ||
| 
						 | 
					6dec1711b4 | ||
| 
						 | 
					a815d59486 | ||
| 
						 | 
					cfc9e2ad0d | ||
| 
						 | 
					6a4b5927bf | ||
| 
						 | 
					c58195eb9e | ||
| 
						 | 
					d5dfcead4d | ||
| 
						 | 
					6358a6006d | ||
| 
						 | 
					7f2758c3ef | ||
| 
						 | 
					4a3e112a8d | ||
| 
						 | 
					89cabd5b3e | ||
| 
						 | 
					19d12a4706 | ||
| 
						 | 
					58dfd56e4b | ||
| 
						 | 
					796ea63151 | ||
| 
						 | 
					6f30754edb | ||
| 
						 | 
					0eab552127 | ||
| 
						 | 
					1b643c5ccc | ||
| 
						 | 
					8983ecd03a | ||
| 
						 | 
					23ad24e4c1 | ||
| 
						 | 
					58e747506e | ||
| 
						 | 
					27b47c494b | ||
| 
						 | 
					70a24d371d | ||
| 
						 | 
					73e3e237ad | ||
| 
						 | 
					dbbbe96df2 | ||
| 
						 | 
					55347fb464 | ||
| 
						 | 
					bae502e8ea | ||
| 
						 | 
					ed9e823f3f | ||
| 
						 | 
					2b8fea5b35 | ||
| 
						 | 
					b3e6b4c29a | ||
| 
						 | 
					c94ff68e7f | ||
| 
						 | 
					3fb96a3438 | ||
| 
						 | 
					7a2b7c0701 | ||
| 
						 | 
					fa7a731ad1 | ||
| 
						 | 
					8be48ebcf0 | ||
| 
						 | 
					123f3abcaa | ||
| 
						 | 
					9f2e43f00a | ||
| 
						 | 
					9fb35b2799 | ||
| 
						 | 
					272572dbf2 | ||
| 
						 | 
					702e4fc787 | ||
| 
						 | 
					511327effe | ||
| 
						 | 
					940e35caea | ||
| 
						 | 
					fca01693dd | ||
| 
						 | 
					8846a3f36f | ||
| 
						 | 
					8002c9e932 | ||
| 
						 | 
					6fd8331e94 | ||
| 
						 | 
					7a667b9028 | ||
| 
						 | 
					67b7cd7a14 | ||
| 
						 | 
					960d79803d | ||
| 
						 | 
					43ef36fa15 | ||
| 
						 | 
					f037d9539e | ||
| 
						 | 
					a3b2f7b5bd | ||
| 
						 | 
					0859145d18 | ||
| 
						 | 
					f6e4122f7f | ||
| 
						 | 
					8e4023fdbc | ||
| 
						 | 
					f10818ec6b | ||
| 
						 | 
					bc2358489b | ||
| 
						 | 
					6e5e682e3a | ||
| 
						 | 
					02c63ce7e8 | ||
| 
						 | 
					fd24d89f89 | ||
| 
						 | 
					685d33a2dd | ||
| 
						 | 
					ca40c9cf19 | ||
| 
						 | 
					8985ea9560 | ||
| 
						 | 
					1832028dfd | ||
| 
						 | 
					316889dab7 | ||
| 
						 | 
					96c80a6549 | ||
| 
						 | 
					fb274e2ed6 | ||
| 
						 | 
					ebe847c04b | ||
| 
						 | 
					fdbf41b3c4 | ||
| 
						 | 
					9dcb9f9537 | ||
| 
						 | 
					1395c877af | ||
| 
						 | 
					969451f18c | ||
| 
						 | 
					259c8d57f5 | ||
| 
						 | 
					2ee07283fa | ||
| 
						 | 
					c85a80617a | ||
| 
						 | 
					5aa8611e43 | ||
| 
						 | 
					86aecd945e | ||
| 
						 | 
					a7a9f4fa13 | ||
| 
						 | 
					22e4c0603b | ||
| 
						 | 
					f3b731460e | ||
| 
						 | 
					d787c6e6c1 | ||
| 
						 | 
					11272b8d00 | ||
| 
						 | 
					1c254e3bb0 | ||
| 
						 | 
					7ade380fad | ||
| 
						 | 
					2a377a37ee | ||
| 
						 | 
					861a9e199d | ||
| 
						 | 
					d4f1e34023 | ||
| 
						 | 
					6d25278a5c | ||
| 
						 | 
					abfb05f04c | ||
| 
						 | 
					9d8e76c5b4 | ||
| 
						 | 
					89662bf54a | ||
| 
						 | 
					520635dfec | ||
| 
						 | 
					ee82a8d75f | ||
| 
						 | 
					967f00cd1b | ||
| 
						 | 
					dda5236d84 | ||
| 
						 | 
					427ca2f108 | ||
| 
						 | 
					e30f2a86f0 | ||
| 
						 | 
					121ef6e976 | ||
| 
						 | 
					e4271ff6f7 | ||
| 
						 | 
					8d3b94734d | ||
| 
						 | 
					9e57150384 | ||
| 
						 | 
					0dc34a7dbe | ||
| 
						 | 
					fbe28dc51a | ||
| 
						 | 
					14e013d075 | ||
| 
						 | 
					9bc4e9530c | ||
| 
						 | 
					cbff505297 | ||
| 
						 | 
					c4aef2d4c7 | ||
| 
						 | 
					2ed6692f76 | ||
| 
						 | 
					f075eabc32 | ||
| 
						 | 
					3d1c9d1667 | ||
| 
						 | 
					0028ad8f54 | ||
| 
						 | 
					4c805f1c27 | ||
| 
						 | 
					505543ad94 | ||
| 
						 | 
					644471c6bf | ||
| 
						 | 
					bf87d7faa1 | ||
| 
						 | 
					be95b65488 | ||
| 
						 | 
					7e9f3bd61a | ||
| 
						 | 
					4a74aa8166 | ||
| 
						 | 
					b4ce4361ce | ||
| 
						 | 
					42a3dd24ad | ||
| 
						 | 
					9129da2e3d | ||
| 
						 | 
					668cdcdd39 | ||
| 
						 | 
					2543ebee10 | ||
| 
						 | 
					104a317163 | ||
| 
						 | 
					921802e6c9 | ||
| 
						 | 
					56cfc1a452 | ||
| 
						 | 
					a14b98be22 | ||
| 
						 | 
					76b5c05acc | ||
| 
						 | 
					8b3f1a448f | ||
| 
						 | 
					3de515c617 | ||
| 
						 | 
					ab199cd9b0 | ||
| 
						 | 
					fc4bc9aa05 | ||
| 
						 | 
					9662a106f0 | ||
| 
						 | 
					06b0538b76 | ||
| 
						 | 
					fb128152a5 | ||
| 
						 | 
					f596af059d | ||
| 
						 | 
					52bb06d250 | ||
| 
						 | 
					f3d22444d3 | 
							
								
								
									
										16
									
								
								.github/ISSUE_TEMPLATE/bug_report.md
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								.github/ISSUE_TEMPLATE/bug_report.md
									
									
									
									
										vendored
									
									
								
							@@ -1,16 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
name: Bug report
 | 
			
		||||
about: Report some misbehaviour in the mod
 | 
			
		||||
labels: bug
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
<!--
 | 
			
		||||
## Before reporting
 | 
			
		||||
 - Search for the bug on the issue tracker. Make sure to look at closed issues too!
 | 
			
		||||
-->
 | 
			
		||||
 | 
			
		||||
## Useful information to include:
 | 
			
		||||
 - Minecraft version
 | 
			
		||||
 - CC: Restitched version
 | 
			
		||||
 - Logs: These will be located in the `logs/` directory of your Minecraft instance. Please upload them as a gist or directly into this editor.
 | 
			
		||||
 - Detailed reproduction steps: sometimes I can spot a bug pretty easily, but often it's much more obscure. The more information I have to help reproduce it, the quicker it'll get fixed.
 | 
			
		||||
							
								
								
									
										34
									
								
								.github/ISSUE_TEMPLATE/bug_report.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								.github/ISSUE_TEMPLATE/bug_report.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
name: Bug report
 | 
			
		||||
description: Report some misbehaviour in the mod
 | 
			
		||||
labels: [ bug ]
 | 
			
		||||
body:
 | 
			
		||||
- type: dropdown
 | 
			
		||||
  id: mc-version
 | 
			
		||||
  attributes:
 | 
			
		||||
    label: Minecraft Version
 | 
			
		||||
    description: What version of Minecraft are you using?
 | 
			
		||||
    options:
 | 
			
		||||
      - 1.16.x
 | 
			
		||||
      - 1.17.x
 | 
			
		||||
      - 1.18.x
 | 
			
		||||
  validations:
 | 
			
		||||
    required: true
 | 
			
		||||
- type: input
 | 
			
		||||
  id: version
 | 
			
		||||
  attributes:
 | 
			
		||||
    label: Version
 | 
			
		||||
    description: "What version of CC: Restitched are you using?"
 | 
			
		||||
    placeholder: "e.g. 1.96.0"
 | 
			
		||||
  validations:
 | 
			
		||||
    required: true
 | 
			
		||||
- type: textarea
 | 
			
		||||
  id: details
 | 
			
		||||
  attributes:
 | 
			
		||||
    label: Details
 | 
			
		||||
    description: |
 | 
			
		||||
      Description of the bug. Please include the following:
 | 
			
		||||
      - Logs: These will be located in the `logs/` directory of your Minecraft
 | 
			
		||||
        instance. Please upload them as a gist or directly into this editor.
 | 
			
		||||
      - Detailed reproduction steps: sometimes I can spot a bug pretty easily,
 | 
			
		||||
        but often it's much more obscure. The more information I have to help
 | 
			
		||||
        reproduce it, the quicker it'll get fixed.
 | 
			
		||||
							
								
								
									
										8
									
								
								.github/ISSUE_TEMPLATE/config.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.github/ISSUE_TEMPLATE/config.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
blank_issues_enabled: false
 | 
			
		||||
contact_links:
 | 
			
		||||
- name: ComputerCraft Discord
 | 
			
		||||
  url: https://discord.computercraft.cc
 | 
			
		||||
  about: Get help on the ComputerCraft Discord.
 | 
			
		||||
- name: GitHub Discussions
 | 
			
		||||
  url: https://github.com/cc-tweaked/CC-Tweaked/discussions
 | 
			
		||||
  about: Or ask questions on GitHub Discussions.
 | 
			
		||||
							
								
								
									
										4
									
								
								.github/ISSUE_TEMPLATE/something_else.md
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								.github/ISSUE_TEMPLATE/something_else.md
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
---
 | 
			
		||||
name: Something else
 | 
			
		||||
about: An issue about something else.
 | 
			
		||||
---
 | 
			
		||||
							
								
								
									
										9
									
								
								.github/workflows/main-ci.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										9
									
								
								.github/workflows/main-ci.yml
									
									
									
									
										vendored
									
									
								
							@@ -9,14 +9,13 @@ jobs:
 | 
			
		||||
 | 
			
		||||
    steps:
 | 
			
		||||
    - uses: actions/checkout@v2
 | 
			
		||||
    - name: Checkout submodules
 | 
			
		||||
      run: git submodule update --init --recursive
 | 
			
		||||
      with:
 | 
			
		||||
        submodules: true
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    - name: Set up Java 8
 | 
			
		||||
    - name: Set up Java 16
 | 
			
		||||
      uses: actions/setup-java@v1
 | 
			
		||||
      with:
 | 
			
		||||
        java-version: 8
 | 
			
		||||
        java-version: 16
 | 
			
		||||
 | 
			
		||||
    - name: Cache gradle dependencies
 | 
			
		||||
      uses: actions/cache@v2
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -21,3 +21,4 @@
 | 
			
		||||
.gradle
 | 
			
		||||
*.DS_Store
 | 
			
		||||
.project
 | 
			
		||||
*.launch
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								.gitpod.Dockerfile
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitpod.Dockerfile
									
									
									
									
										vendored
									
									
								
							@@ -16,4 +16,4 @@ RUN sudo apt-get -q update && \
 | 
			
		||||
    sudo apt install -yq openjdk-8-jdk openjdk-16-jdk
 | 
			
		||||
 | 
			
		||||
# This is so that you can use java 8 until such a time as you switch to java 16
 | 
			
		||||
RUN sudo update-java-alternatives --set java-1.8.0-openjdk-amd64
 | 
			
		||||
RUN sudo update-java-alternatives --set java-1.16.0-openjdk-amd64
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										101
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										101
									
								
								README.md
									
									
									
									
									
								
							@@ -1,66 +1,61 @@
 | 
			
		||||
# CC:Restitched
 | 
			
		||||
# CC:R Version VS CC:T Version
 | 
			
		||||
CC:R Strives to maintain perfect pairity with CC:T, however in some cases this is not possible, so CC:R might have a "newer" version than what CC:T has, these newer versions will be primarily bugfixes and the like because fabric is "weird" when porting a forge mod
 | 
			
		||||
 | 
			
		||||
<img src="logo.png" alt="CC: Restitched" width="100%"/>
 | 
			
		||||
 | 
			
		||||
[](https://github.com/Merith-TK/cc-restitched/actions "Current build status") [](https://www.curseforge.com/minecraft/mc-mods/cc-restitched-updated "Download CC: Restitched on CurseForge")
 | 
			
		||||
[](https://github.com/cc-tweaked/cc-restitched/actions "Current build status")
 | 
			
		||||
[](https://www.curseforge.com/minecraft/mc-mods/cc-restitched "Download CC:  Restitched on CurseForge")
 | 
			
		||||
[](https://gitpod.io/#https://github.com/cc-tweaked/cc-restitched/tree/1.17.1)
 | 
			
		||||
 | 
			
		||||
[](https://gitpod.io/#https://github.com/Merith-TK/cc-restitched/)
 | 
			
		||||
# What is CC: Restitched?
 | 
			
		||||
This is a fabric port of [SquidDev-CC/CC-Tweaked](https://github.com/SquidDev-CC/CC-Tweaked). The work is a continuation of [Zundrel/cc-tweaked-fabric](https://github.com/Zundrel/cc-tweaked-fabric).
 | 
			
		||||
 | 
			
		||||
## What is CC: Restiched
 | 
			
		||||
This is an fork of [Zundrel/cc-tweaked-fabric](https://github.com/Zundrel/cc-tweaked-fabric) who's goal was to port [SquidDev-CC/CC-Tweaked](https://github.com/SquidDev-CC/CC-Tweaked) to the [Fabric](https://fabricmc.net/) modloader. I picked up maintaining the mod because the team working on Zundrel's fork, admitted they had gotten lethargic so I picked it up to make it equal with CC:T
 | 
			
		||||
## CC: Restitched vs. CC: Tweaked
 | 
			
		||||
CC: R tries to maintain parity with CC: T, but may be behind or divergent in some areas. If you notice a disparity please open an issue. CC: R major and minor version numbers indicate parity with the major features of that version of CC: T. Patch version numbers will not align.
 | 
			
		||||
 | 
			
		||||
## Resource Packs
 | 
			
		||||
This mod includes textures that are more in-line with the style of Mojang's new texture-artist, Jappa. If you prefer the original textures, enable the "Classic" resource pack provided by the mod.
 | 
			
		||||
This mod includes textures by [Jummit](https://github.com/Jummit) that are more in line with the style of Mojang's new texture-artist, Jappa. If you prefer the original textures, enable the "Classic" resource pack.
 | 
			
		||||
 | 
			
		||||
<img src="https://raw.githubusercontent.com/3prm3/cc-pack/main/pack.png" alt="CC: Restitched" width="16"  height="16"/> [3prm3/cc-pack](https://github.com/3prm3/cc-pack/)
 | 
			
		||||
We also have a second resourcepack made by [3prm3](https://github.com/3prm3), it features a complete overhaul and can be enabled by enabling the `overhaul` resource pack, go check out his resource pack over here!
 | 
			
		||||
 | 
			
		||||
## Major Tasks Planned
 | 
			
		||||
* Rewrite the config system
 | 
			
		||||
    * **Planned for 1.96.3 release**
 | 
			
		||||
	* it currently sets the values that would normally be read from `config/computercraft.json` to the default values, because it does not read the file at all
 | 
			
		||||
<img src="https://raw.githubusercontent.com/3prm3/cc-pack/main/pack.png" alt="CC: Restitched" width="16"  height="16"/> We also have a second resourcepack made by [3prm3](https://github.com/3prm3), it features a complete overhaul and can be enabled by enabling the `overhaul` resource pack, go check out his resource pack over [here](https://github.com/3prm3/cc-pack/)!
 | 
			
		||||
 | 
			
		||||
## Contributing
 | 
			
		||||
Any contribution is welcome, be that using the mod, reporting bugs or contributing code. In order to start helping develop CC:R there are a few rules
 | 
			
		||||
1) Any updates that port commits from CC:T, ***MUST*** follow the format defined in [patchwork.md](patchwork.md) otherwise they will not be accepted,
 | 
			
		||||
	* Commit Message must be the same as it is in CC:T,
 | 
			
		||||
	* patchwork.md must be updated in the following format
 | 
			
		||||
	> Comments, optional but useful if you had to do something 	differently than in CC:T outside of [Fabric](https://fabricmc.net/)/[Forge](https://mcforge.readthedocs.io/en/1.16.x/) differences
 | 
			
		||||
	>
 | 
			
		||||
	> \`\`\`
 | 
			
		||||
	>
 | 
			
		||||
	>commitID
 | 
			
		||||
	>
 | 
			
		||||
	> commit title
 | 
			
		||||
	>
 | 
			
		||||
	> commit desc
 | 
			
		||||
	>
 | 
			
		||||
	> \`\`\`
 | 
			
		||||
2) Follow the [Fabric](https://fabricmc.net/) programming guidelines as close as possible. This means you have to use [`loom`](https://fabricmc.net/wiki/tutorial:mappings) mappings,
 | 
			
		||||
3) You cannot intentionally implement bugs and security vulnerabilities
 | 
			
		||||
4) Unless the commit is a ["patchwork"](https://github.com/Merith-TK/cc-restitched/blob/fabric/patchwork.md) compliant commit, (IE: taken from CC:T), the lua code is off limits
 | 
			
		||||
Any contribution is welcome, be that using the mod, reporting bugs or contributing code. In order to start helping develop CC: R there are a few rules;
 | 
			
		||||
1) Make sure your code follows the checkstyle rules. You can test this by running `./gradle build` or `./gradle check`.
 | 
			
		||||
2)  Do not alter the lua code unless those changes are taken directly from CC: Tweaked. If you wish to contribute changes to the in game rom please contribute upstream at [CC-Tweaked](https://github.com/SquidDev-CC/CC-Tweaked).
 | 
			
		||||
 | 
			
		||||
# Does this work Fabric's many rendering mods?
 | 
			
		||||
* [ YES ] Sodium
 | 
			
		||||
* [ YES ] Optifine
 | 
			
		||||
	* Works with VBO Rendering (automatically set)
 | 
			
		||||
	* No issues
 | 
			
		||||
* [ EHH ] Iris Shaders
 | 
			
		||||
	* "Works" with TBO Rendering (Default)
 | 
			
		||||
	* Crashes with VBO Rendering
 | 
			
		||||
	* <details>
 | 
			
		||||
		<summary>Shaders are broken</summary>
 | 
			
		||||
 | 
			
		||||
		* Shaders will cause varrying results ranging from monitors being invisible, to straight up crashing.
 | 
			
		||||
		* Not using shaders will result in odd Z-Fighting of the monitor display and the transparent texture
 | 
			
		||||
			- 
 | 
			
		||||
			- 
 | 
			
		||||
		</details>
 | 
			
		||||
* [ YES ] Canvas
 | 
			
		||||
	* Works with TBO Rendering (Default)
 | 
			
		||||
	* Scuffed with VBO Rendering
 | 
			
		||||
	* <details>
 | 
			
		||||
		<summary>VBO is broken</summary>
 | 
			
		||||
 | 
			
		||||
  		Monitors are just... scuffed beyond belief.
 | 
			
		||||
		- 
 | 
			
		||||
		- 
 | 
			
		||||
			* The content to the left is supposed to be on the monitors to the right, also the bottom one is supposed to `black/white` not colored.
 | 
			
		||||
		* Turtle Texture for some reason?
 | 
			
		||||
			- 
 | 
			
		||||
		</details>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Bleeding Edge Builds
 | 
			
		||||
Bleeding edge builds can be found [here](https://github.com/Merith-TK/cc-restitched/actions) at Github Actions.
 | 
			
		||||
Bleeding edge builds can be found [here](https://github.com/cc-tweaked/cc-restitched/actions) at Github Actions.
 | 
			
		||||
 | 
			
		||||
## Community
 | 
			
		||||
If you need help getting started with CC: Tweaked, want to show off your latest project, or just want to chat about ComputerCraft, here is the [Forum](https://forums.computercraft.cc/) and the [Discord](https://discord.gg/H2UyJXe)
 | 
			
		||||
If you need help getting started with CC: Restitched, want to show off your latest project, or just want to chat about ComputerCraft, here is the [Forum](https://forums.computercraft.cc/) and the [Discord](https://discord.gg/H2UyJXe).
 | 
			
		||||
 | 
			
		||||
## Known Issues
 | 
			
		||||
Main Known issue
 | 
			
		||||
* Mods that add blocks that can be used as peripherals for CC:T On forge, don't work with CC:R.
 | 
			
		||||
	* This is because of the differences between forge and fabric, and that mod devs, to my knowledge have not agreed upon a standard method in which to implement cross compatibility between mods,
 | 
			
		||||
* [Fixed (d10f297c): please report if bug persists]</br> ~~Storage Peripherals throw a java "StackOverflowError" when using `pushItems()`,~~
 | 
			
		||||
    * ~~Work around, you are probably using `pushItems(chest, 1)` or similar. please use `pushItems(chest, 1, nil, 1)`.~~
 | 
			
		||||
* Computers will not run built in commands, saying "File not found"
 | 
			
		||||
    * This is a know bug, dont know what causes it, but just restart the computer (`ctrl+r` for one second) and it will work again
 | 
			
		||||
    * Occurs when server runs `/reload` or a datapack is updated
 | 
			
		||||
 | 
			
		||||
## Perpherals
 | 
			
		||||
Unfortunately, unlike the original CC:Tweaked project, CC:Restitched, does not have any actual peripheral mods, currently the only one we have is an example for mod devs to get started with making/adding the peripheral API to their mods!
 | 
			
		||||
 | 
			
		||||
If your a mod dev made a mod with CC:R peripheral support, OR if your a player who found a mod with CC:R support, please open an [issue here](https://github.com/Merith-TK/cc-restitched/issues/new?assignees=&labels=peripheralShoutout&template=peripheral_shoutout.md) to let us know so we can add it to the list!
 | 
			
		||||
 | 
			
		||||
*  [CC Peripheral Test](https://github.com/Toad-Dev/cc-peripheral-test)
 | 
			
		||||
	* This is an example mod for how to make peripherals that work as a block, or as a turtle upgrade!
 | 
			
		||||
## Perpheral mods
 | 
			
		||||
Unfortunately, CC: Restitched does not have as many peripherals mods available as CC: Tweaked. If you're an interested mod developer, please check out our `api` package. If you've already made a mod with CC: R peripheral support OR if you're a player who found a mod with ComputerCraft integration, please open an [issue here](https://github.com/cc-tweaked/cc-restitched/issues/new?assignees=&labels=peripheralShoutout&template=peripheral_shoutout.md) to let us know and we'll add it to the list!
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										167
									
								
								build.gradle
									
									
									
									
									
								
							
							
						
						
									
										167
									
								
								build.gradle
									
									
									
									
									
								
							@@ -1,48 +1,80 @@
 | 
			
		||||
plugins {
 | 
			
		||||
    id 'fabric-loom' version '0.7-SNAPSHOT'
 | 
			
		||||
    id 'maven-publish'
 | 
			
		||||
    id "checkstyle"
 | 
			
		||||
    id "com.github.hierynomus.license" version "0.15.0"
 | 
			
		||||
    id "jacoco"
 | 
			
		||||
    id "maven-publish"
 | 
			
		||||
    id "com.github.hierynomus.license" version "0.16.1"
 | 
			
		||||
    id "org.jetbrains.kotlin.jvm" version "1.5.21"
 | 
			
		||||
    id 'fabric-loom' version '0.10-SNAPSHOT'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sourceCompatibility = JavaVersion.VERSION_1_8
 | 
			
		||||
targetCompatibility = JavaVersion.VERSION_1_8
 | 
			
		||||
def javaVersion = JavaLanguageVersion.of(16)
 | 
			
		||||
java {
 | 
			
		||||
    toolchain {
 | 
			
		||||
        languageVersion = javaVersion
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    withSourcesJar()
 | 
			
		||||
    withJavadocJar()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
tasks.withType(JavaExec).configureEach {
 | 
			
		||||
    javaLauncher = javaToolchains.launcherFor {
 | 
			
		||||
        languageVersion = javaVersion
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
version = mod_version
 | 
			
		||||
 | 
			
		||||
group = "dan200.computercraft"
 | 
			
		||||
archivesBaseName = "cc-restiched"
 | 
			
		||||
archivesBaseName = "cc-restitched"
 | 
			
		||||
 | 
			
		||||
sourceSets {
 | 
			
		||||
    main.resources {
 | 
			
		||||
        srcDir 'src/generated/resources'
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    testMod {}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
loom {
 | 
			
		||||
    accessWidenerPath = file("src/main/resources/cc.accesswidener")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
repositories {
 | 
			
		||||
    mavenCentral()
 | 
			
		||||
    maven { url 'https://jitpack.io' }
 | 
			
		||||
    maven { url "https://maven.shedaniel.me/" }
 | 
			
		||||
    maven {
 | 
			
		||||
        name "SquidDev"
 | 
			
		||||
        url "https://squiddev.cc/maven"
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO: Limit these to a set of groups.
 | 
			
		||||
    maven { url "https://maven.shedaniel.me/" }
 | 
			
		||||
    maven { url "https://maven.terraformersmc.com/" }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
configurations {
 | 
			
		||||
    shade
 | 
			
		||||
    implementation.extendsFrom shade
 | 
			
		||||
    cctJavadoc
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
dependencies {
 | 
			
		||||
    checkstyle "com.puppycrawl.tools:checkstyle:8.25"
 | 
			
		||||
    checkstyle "com.puppycrawl.tools:checkstyle:8.45"
 | 
			
		||||
 | 
			
		||||
    minecraft "com.mojang:minecraft:${mc_version}"
 | 
			
		||||
    mappings "net.fabricmc:yarn:${mc_version}+build.${mappings_version}:v2"
 | 
			
		||||
    mappings loom.officialMojangMappings()
 | 
			
		||||
    modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
 | 
			
		||||
    modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}"
 | 
			
		||||
 | 
			
		||||
    modApi("me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}") {
 | 
			
		||||
        exclude(group: "net.fabricmc.fabric-api")
 | 
			
		||||
    }
 | 
			
		||||
    modImplementation "io.github.prospector:modmenu:${modmenu_version}"
 | 
			
		||||
    modImplementation "com.terraformersmc:modmenu:${modmenu_version}"
 | 
			
		||||
    modImplementation "me.shedaniel.cloth.api:cloth-utils-v1:${cloth_api_version}"
 | 
			
		||||
 | 
			
		||||
    implementation 'com.electronwill.night-config:toml:3.6.3'
 | 
			
		||||
    implementation 'com.google.code.findbugs:jsr305:3.0.2'
 | 
			
		||||
 | 
			
		||||
    compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
 | 
			
		||||
 | 
			
		||||
    shade 'org.squiddev:Cobalt:0.5.2-SNAPSHOT'
 | 
			
		||||
 | 
			
		||||
@@ -51,44 +83,114 @@ dependencies {
 | 
			
		||||
    include 'com.electronwill.night-config:toml:3.6.3'
 | 
			
		||||
    include "me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}"
 | 
			
		||||
 | 
			
		||||
    modRuntime "me.shedaniel:RoughlyEnoughItems-api:5.12.248"
 | 
			
		||||
    modRuntime "me.shedaniel:RoughlyEnoughItems:5.12.248"
 | 
			
		||||
    modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:6.0.254-alpha"
 | 
			
		||||
    modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:6.0.254-alpha"
 | 
			
		||||
 | 
			
		||||
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
 | 
			
		||||
    testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.0'
 | 
			
		||||
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
 | 
			
		||||
    testImplementation 'org.hamcrest:hamcrest:2.2'
 | 
			
		||||
    testImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21'
 | 
			
		||||
    testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1'
 | 
			
		||||
 | 
			
		||||
    cctJavadoc 'cc.tweaked:cct-javadoc:1.4.1'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
processResources {
 | 
			
		||||
    inputs.property "version", project.version
 | 
			
		||||
 | 
			
		||||
    from(sourceSets.main.resources.srcDirs) {
 | 
			
		||||
        include "fabric.mod.json"
 | 
			
		||||
        expand "version": project.version
 | 
			
		||||
    }
 | 
			
		||||
    def hash = 'none'
 | 
			
		||||
    Set<String> contributors = []
 | 
			
		||||
    try {
 | 
			
		||||
        hash = ["git", "-C", projectDir, "rev-parse", "HEAD"].execute().text.trim()
 | 
			
		||||
 | 
			
		||||
    from(sourceSets.main.resources.srcDirs) {
 | 
			
		||||
        exclude "fabric.mod.json"
 | 
			
		||||
        def blacklist = ['GitHub', 'dan200', 'Daniel Ratcliffe']
 | 
			
		||||
        ["git", "-C", projectDir, "log", "--format=tformat:%an%n%cn"].execute().text.split('\n').each {
 | 
			
		||||
            if (!blacklist.contains(it)) contributors.add(it)
 | 
			
		||||
        }
 | 
			
		||||
    } catch (Exception e) {
 | 
			
		||||
        e.printStackTrace()
 | 
			
		||||
    }
 | 
			
		||||
    inputs.property "commithash", hash
 | 
			
		||||
    duplicatesStrategy = DuplicatesStrategy.INCLUDE
 | 
			
		||||
 | 
			
		||||
    filesMatching(["fabric.mod.json", "data/computercraft/lua/rom/help/credits.txt"]) {
 | 
			
		||||
        expand(
 | 
			
		||||
            'version': mod_version,
 | 
			
		||||
            'mcversion': mc_version,
 | 
			
		||||
            'gitcontributors': contributors.sort(false, String.CASE_INSENSITIVE_ORDER).join('\n')
 | 
			
		||||
        )
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
 | 
			
		||||
// this fixes some edge cases with special characters not displaying correctly
 | 
			
		||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
 | 
			
		||||
tasks.withType(JavaCompile) {
 | 
			
		||||
    options.encoding = "UTF-8"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
 | 
			
		||||
// if it is present.
 | 
			
		||||
// If you remove this task, sources will not be generated.
 | 
			
		||||
task sourcesJar(type: Jar, dependsOn: classes) {
 | 
			
		||||
    classifier = "sources"
 | 
			
		||||
    from sourceSets.main.allSource
 | 
			
		||||
javadoc {
 | 
			
		||||
    include "dan200/computercraft/api/**/*.java"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
task luaJavadoc(type: Javadoc) {
 | 
			
		||||
    description "Generates documentation for Java-side Lua functions."
 | 
			
		||||
    group "documentation"
 | 
			
		||||
 | 
			
		||||
    source = sourceSets.main.allJava
 | 
			
		||||
    destinationDir = file("${project.docsDir}/luaJavadoc")
 | 
			
		||||
    classpath = sourceSets.main.compileClasspath
 | 
			
		||||
 | 
			
		||||
    options.docletpath = configurations.cctJavadoc.files as List
 | 
			
		||||
    options.doclet = "cc.tweaked.javadoc.LuaDoclet"
 | 
			
		||||
    options.noTimestamp = false
 | 
			
		||||
 | 
			
		||||
    javadocTool = javaToolchains.javadocToolFor {
 | 
			
		||||
        languageVersion = javaVersion
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
jar {
 | 
			
		||||
    from "LICENSE"
 | 
			
		||||
    manifest {
 | 
			
		||||
        attributes([
 | 
			
		||||
            "Specification-Title"     : "computercraft",
 | 
			
		||||
            "Specification-Version"   : "1",
 | 
			
		||||
            "Implementation-Title"    : "CC: Restitched",
 | 
			
		||||
            "Implementation-Version"  : "${mod_version}",
 | 
			
		||||
            "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
 | 
			
		||||
        ])
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    from configurations.shade.collect { it.isDirectory() ? it : zipTree(it) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[compileJava, compileTestJava].forEach {
 | 
			
		||||
    it.configure {
 | 
			
		||||
        options.compilerArgs << "-Xlint" << "-Xlint:-processing"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sourcesJar {
 | 
			
		||||
    duplicatesStrategy = DuplicatesStrategy.INCLUDE
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Check tasks
 | 
			
		||||
 | 
			
		||||
test {
 | 
			
		||||
    useJUnitPlatform()
 | 
			
		||||
    testLogging {
 | 
			
		||||
        events "skipped", "failed"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
jacocoTestReport {
 | 
			
		||||
    dependsOn('test')
 | 
			
		||||
    reports {
 | 
			
		||||
        xml.required = true
 | 
			
		||||
        html.required = true
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
check.dependsOn jacocoTestReport
 | 
			
		||||
 | 
			
		||||
import com.hierynomus.gradle.license.tasks.LicenseCheck
 | 
			
		||||
import com.hierynomus.gradle.license.tasks.LicenseFormat
 | 
			
		||||
@@ -108,7 +210,7 @@ license {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[licenseTest, licenseFormatTest].forEach {
 | 
			
		||||
[licenseTest, licenseFormatTest, licenseTestMod, licenseFormatTestMod].forEach {
 | 
			
		||||
    it.configure {
 | 
			
		||||
        include("**/*.java")
 | 
			
		||||
        header file('config/license/main.txt')
 | 
			
		||||
@@ -121,9 +223,8 @@ gradle.projectsEvaluated {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
task licenseAPI(type: LicenseCheck);
 | 
			
		||||
task licenseFormatAPI(type: LicenseFormat);
 | 
			
		||||
task licenseAPI(type: LicenseCheck)
 | 
			
		||||
task licenseFormatAPI(type: LicenseFormat)
 | 
			
		||||
[licenseAPI, licenseFormatAPI].forEach {
 | 
			
		||||
    it.configure {
 | 
			
		||||
        source = sourceSets.main.java
 | 
			
		||||
 
 | 
			
		||||
@@ -58,13 +58,20 @@
 | 
			
		||||
        <module name="SimplifyBooleanExpression" />
 | 
			
		||||
        <module name="SimplifyBooleanReturn" />
 | 
			
		||||
        <module name="StringLiteralEquality" />
 | 
			
		||||
        <module name="UnnecessaryParentheses" />
 | 
			
		||||
        <module name="UnnecessaryParentheses">
 | 
			
		||||
            <!-- Default minus LAND. -->
 | 
			
		||||
            <property name="tokens" value="EXPR,IDENT,NUM_DOUBLE,NUM_FLOAT,NUM_INT,NUM_LONG,STRING_LITERAL,LITERAL_NULL,LITERAL_FALSE,LITERAL_TRUE,ASSIGN,BAND_ASSIGN,BOR_ASSIGN,BSR_ASSIGN,BXOR_ASSIGN,DIV_ASSIGN,MINUS_ASSIGN,MOD_ASSIGN,PLUS_ASSIGN,SL_ASSIGN,SR_ASSIGN,STAR_ASSIGN,LAMBDA,TEXT_BLOCK_LITERAL_BEGIN,LITERAL_INSTANCEOF,GT,LT,GE,LE,EQUAL,NOT_EQUAL,UNARY_MINUS,UNARY_PLUS,INC,DEC,LNOT,BNOT,POST_INC,POST_DEC" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="UnnecessarySemicolonAfterTypeMemberDeclaration" />
 | 
			
		||||
        <module name="UnnecessarySemicolonInTryWithResources" />
 | 
			
		||||
        <module name="UnnecessarySemicolonInEnumeration" />
 | 
			
		||||
 | 
			
		||||
        <!-- Imports -->
 | 
			
		||||
        <module name="CustomImportOrder" />
 | 
			
		||||
        <module name="CustomImportOrder">
 | 
			
		||||
            <property name="customImportOrderRules"
 | 
			
		||||
                value="THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE###STATIC"
 | 
			
		||||
            />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="IllegalImport" />
 | 
			
		||||
        <module name="RedundantImport" />
 | 
			
		||||
        <module name="UnusedImports" />
 | 
			
		||||
@@ -149,8 +156,13 @@
 | 
			
		||||
            <property name="tokens" value="COMMA" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="WhitespaceAround">
 | 
			
		||||
            <property name="allowEmptyConstructors" value="true" />
 | 
			
		||||
            <property name="ignoreEnhancedForColon" value="false" />
 | 
			
		||||
            <!-- Allow empty functions -->
 | 
			
		||||
            <property name="allowEmptyLambdas" value="true" />
 | 
			
		||||
            <property name="allowEmptyMethods" value="true" />
 | 
			
		||||
            <property name="allowEmptyConstructors" value="true" />
 | 
			
		||||
            <property name="allowEmptyTypes" value="true" />
 | 
			
		||||
 | 
			
		||||
            <property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,EQUAL,GE,GT,LAMBDA,LAND,LCURLY,LE,LITERAL_RETURN,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND" />
 | 
			
		||||
        </module>
 | 
			
		||||
    </module>
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,9 @@
 | 
			
		||||
    <suppress checks="StaticVariableName" files=".*[\\/]ComputerCraft.java" />
 | 
			
		||||
    <suppress checks="StaticVariableName" files=".*[\\/]ComputerCraftAPI.java" />
 | 
			
		||||
 | 
			
		||||
    <!-- Some shadowed fields in mixins can't be renamed -->
 | 
			
		||||
    <suppress checks="StaticVariableName" files=".*[\\/]mixin[\\/].*" />
 | 
			
		||||
 | 
			
		||||
    <!-- The commands API is documented in Lua. -->
 | 
			
		||||
    <suppress checks="SummaryJavadocCheck" files=".*[\\/]CommandAPI.java" />
 | 
			
		||||
</suppressions>
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
# See https://pre-commit.com/hooks.html for more hooks
 | 
			
		||||
repos:
 | 
			
		||||
- repo: https://github.com/pre-commit/pre-commit-hooks
 | 
			
		||||
  rev: v3.2.0
 | 
			
		||||
  rev: v4.0.1
 | 
			
		||||
  hooks:
 | 
			
		||||
  - id: trailing-whitespace
 | 
			
		||||
  - id: end-of-file-fixer
 | 
			
		||||
@@ -16,7 +16,7 @@ repos:
 | 
			
		||||
    exclude: "tsconfig\\.json$"
 | 
			
		||||
 | 
			
		||||
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
 | 
			
		||||
  rev: 2.3.5
 | 
			
		||||
  rev: 2.3.54
 | 
			
		||||
  hooks:
 | 
			
		||||
  - id: editorconfig-checker
 | 
			
		||||
    args: ['-disable-indentation']
 | 
			
		||||
@@ -38,6 +38,13 @@ repos:
 | 
			
		||||
    entry: ./gradlew licenseFormat
 | 
			
		||||
    pass_filenames: false
 | 
			
		||||
    require_serial: true
 | 
			
		||||
  - id: illuaminate
 | 
			
		||||
    name: Check Lua code
 | 
			
		||||
    files: ".*\\.(lua|java|md)"
 | 
			
		||||
    language: script
 | 
			
		||||
    entry: config/pre-commit/illuaminate-lint.sh
 | 
			
		||||
    pass_filenames: false
 | 
			
		||||
    require_serial: true
 | 
			
		||||
 | 
			
		||||
exclude: |
 | 
			
		||||
  (?x)^(
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										21
									
								
								doc/events/alarm.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								doc/events/alarm.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] alarm
 | 
			
		||||
see: os.setAlarm To start an alarm.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{timer} event is fired when an alarm started with @{os.setAlarm} completes.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{number}: The ID of the alarm that finished.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Starts a timer and then prints its ID:
 | 
			
		||||
```lua
 | 
			
		||||
local alarmID = os.setAlarm(os.time() + 0.05)
 | 
			
		||||
local event, id
 | 
			
		||||
repeat
 | 
			
		||||
    event, id = os.pullEvent("alarm")
 | 
			
		||||
until id == alarmID
 | 
			
		||||
print("Alarm with ID " .. id .. " was fired")
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										24
									
								
								doc/events/char.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								doc/events/char.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] char
 | 
			
		||||
see: key To listen to any key press.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{char} event is fired when a character is _typed_ on the keyboard.
 | 
			
		||||
 | 
			
		||||
The @{char} event is different to a key press. Sometimes multiple key presses may result in one character being
 | 
			
		||||
typed (for instance, on some European keyboards). Similarly, some keys (e.g. <kbd>Ctrl</kbd>) do not have any
 | 
			
		||||
corresponding character. The @{key} should be used if you want to listen to key presses themselves.
 | 
			
		||||
 | 
			
		||||
## Return values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string}: The string representing the character that was pressed.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints each character the user presses:
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, character = os.pullEvent("char")
 | 
			
		||||
  print(character .. " was pressed.")
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										18
									
								
								doc/events/computer_command.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								doc/events/computer_command.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] computer_command
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{computer_command} event is fired when the `/computercraft queue` command is run for the current computer.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
... @{string}: The arguments passed to the command.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints the contents of messages sent:
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event = {os.pullEvent("computer_command")}
 | 
			
		||||
  print("Received message:", table.unpack(event, 2))
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										19
									
								
								doc/events/disk.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								doc/events/disk.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] disk
 | 
			
		||||
see: disk_eject For the event sent when a disk is removed.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{disk} event is fired when a disk is inserted into an adjacent or networked disk drive.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string}: The side of the disk drive that had a disk inserted.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints a message when a disk is inserted:
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, side = os.pullEvent("disk")
 | 
			
		||||
  print("Inserted a disk on side " .. side)
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										19
									
								
								doc/events/disk_eject.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								doc/events/disk_eject.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] disk_eject
 | 
			
		||||
see: disk For the event sent when a disk is inserted.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{disk_eject} event is fired when a disk is removed from an adjacent or networked disk drive.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string}: The side of the disk drive that had a disk removed.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints a message when a disk is removed:
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, side = os.pullEvent("disk_eject")
 | 
			
		||||
  print("Removed a disk on side " .. side)
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										14
									
								
								doc/events/http_check.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								doc/events/http_check.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] http_check
 | 
			
		||||
see: http.checkURLAsync To check a URL asynchronously.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{http_check} event is fired when a URL check finishes.
 | 
			
		||||
 | 
			
		||||
This event is normally handled inside @{http.checkURL}, but it can still be seen when using @{http.checkURLAsync}.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string}: The URL requested to be checked.
 | 
			
		||||
3. @{boolean}: Whether the check succeeded.
 | 
			
		||||
4. @{string|nil}: If the check failed, a reason explaining why the check failed.
 | 
			
		||||
							
								
								
									
										39
									
								
								doc/events/http_failure.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								doc/events/http_failure.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] http_failure
 | 
			
		||||
see: http.request To send an HTTP request.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{http_failure} event is fired when an HTTP request fails.
 | 
			
		||||
 | 
			
		||||
This event is normally handled inside @{http.get} and @{http.post}, but it can still be seen when using @{http.request}.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string}: The URL of the site requested.
 | 
			
		||||
3. @{string}: An error describing the failure.
 | 
			
		||||
4. @{http.Response|nil}: A response handle if the connection succeeded, but the server's response indicated failure.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints an error why the website cannot be contacted:
 | 
			
		||||
```lua
 | 
			
		||||
local myURL = "https://does.not.exist.tweaked.cc"
 | 
			
		||||
http.request(myURL)
 | 
			
		||||
local event, url, err
 | 
			
		||||
repeat
 | 
			
		||||
    event, url, err = os.pullEvent("http_failure")
 | 
			
		||||
until url == myURL
 | 
			
		||||
print("The URL " .. url .. " could not be reached: " .. err)
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Prints the contents of a webpage that does not exist:
 | 
			
		||||
```lua
 | 
			
		||||
local myURL = "https://tweaked.cc/this/does/not/exist"
 | 
			
		||||
http.request(myURL)
 | 
			
		||||
local event, url, err, handle
 | 
			
		||||
repeat
 | 
			
		||||
    event, url, err, handle = os.pullEvent("http_failure")
 | 
			
		||||
until url == myURL
 | 
			
		||||
print("The URL " .. url .. " could not be reached: " .. err)
 | 
			
		||||
print(handle.getResponseCode())
 | 
			
		||||
handle.close()
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										27
									
								
								doc/events/http_success.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								doc/events/http_success.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] http_success
 | 
			
		||||
see: http.request To make an HTTP request.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{http_success} event is fired when an HTTP request returns successfully.
 | 
			
		||||
 | 
			
		||||
This event is normally handled inside @{http.get} and @{http.post}, but it can still be seen when using @{http.request}.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string}: The URL of the site requested.
 | 
			
		||||
3. @{http.Response}: The handle for the response text.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints the content of a website (this may fail if the request fails):
 | 
			
		||||
```lua
 | 
			
		||||
local myURL = "https://tweaked.cc/"
 | 
			
		||||
http.request(myURL)
 | 
			
		||||
local event, url, handle
 | 
			
		||||
repeat
 | 
			
		||||
    event, url, handle = os.pullEvent("http_success")
 | 
			
		||||
until url == myURL
 | 
			
		||||
print("Contents of " .. url .. ":")
 | 
			
		||||
print(handle.readAll())
 | 
			
		||||
handle.close()
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										26
									
								
								doc/events/key.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								doc/events/key.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] key
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
This event is fired when any key is pressed while the terminal is focused.
 | 
			
		||||
 | 
			
		||||
This event returns a numerical "key code" (for instance, <kbd>F1</kbd> is 290). This value may vary between versions and
 | 
			
		||||
so it is recommended to use the constants in the @{keys} API rather than hard coding numeric values.
 | 
			
		||||
 | 
			
		||||
If the button pressed represented a printable character, then the @{key} event will be followed immediately by a @{char}
 | 
			
		||||
event. If you are consuming text input, use a @{char} event instead!
 | 
			
		||||
 | 
			
		||||
## Return values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{number}: The numerical key value of the key pressed.
 | 
			
		||||
3. @{boolean}: Whether the key event was generated while holding the key (@{true}), rather than pressing it the first time (@{false}).
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints each key when the user presses it, and if the key is being held.
 | 
			
		||||
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, key, is_held = os.pullEvent("key")
 | 
			
		||||
  print(("%s held=%s"):format(keys.getName(key), is_held))
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										24
									
								
								doc/events/key_up.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								doc/events/key_up.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] key_up
 | 
			
		||||
see: keys For a lookup table of the given keys.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
Fired whenever a key is released (or the terminal is closed while a key was being pressed).
 | 
			
		||||
 | 
			
		||||
This event returns a numerical "key code" (for instance, <kbd>F1</kbd> is 290). This value may vary between versions and
 | 
			
		||||
so it is recommended to use the constants in the @{keys} API rather than hard coding numeric values.
 | 
			
		||||
 | 
			
		||||
## Return values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{number}: The numerical key value of the key pressed.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints each key released on the keyboard whenever a @{key_up} event is fired.
 | 
			
		||||
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, key = os.pullEvent("key_up")
 | 
			
		||||
  local name = keys.getName(key) or "unknown key"
 | 
			
		||||
  print(name .. " was released.")
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										22
									
								
								doc/events/modem_message.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								doc/events/modem_message.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] modem_message
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{modem_message} event is fired when a message is received on an open channel on any modem.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string}: The side of the modem that received the message.
 | 
			
		||||
3. @{number}: The channel that the message was sent on.
 | 
			
		||||
4. @{number}: The reply channel set by the sender.
 | 
			
		||||
5. @{any}: The message as sent by the sender.
 | 
			
		||||
6. @{number}: The distance between the sender and the receiver, in blocks (decimal).
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints a message when one is sent:
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
 | 
			
		||||
  print(("Message received on side %s on channel %d (reply to %d) from %f blocks away with message %s"):format(side, channel, replyChannel, distance, tostring(message)))
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										18
									
								
								doc/events/monitor_resize.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								doc/events/monitor_resize.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] monitor_resize
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{monitor_resize} event is fired when an adjacent or networked monitor's size is changed.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string}: The side or network ID of the monitor that resized.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints a message when a monitor is resized:
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, side = os.pullEvent("monitor_resize")
 | 
			
		||||
  print("The monitor on side " .. side .. " was resized.")
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										20
									
								
								doc/events/monitor_touch.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								doc/events/monitor_touch.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] monitor_touch
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{monitor_touch} event is fired when an adjacent or networked Advanced Monitor is right-clicked.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string}: The side or network ID of the monitor that was touched.
 | 
			
		||||
3. @{number}: The X coordinate of the touch, in characters.
 | 
			
		||||
4. @{number}: The Y coordinate of the touch, in characters.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints a message when a monitor is touched:
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, side, x, y = os.pullEvent("monitor_touch")
 | 
			
		||||
  print("The monitor on side " .. side .. " was touched at (" .. x .. ", " .. y .. ")")
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										34
									
								
								doc/events/mouse_click.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								doc/events/mouse_click.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] mouse_click
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
This event is fired when the terminal is clicked with a mouse. This event is only fired on advanced computers (including
 | 
			
		||||
advanced turtles and pocket computers).
 | 
			
		||||
 | 
			
		||||
## Return values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{number}: The mouse button that was clicked.
 | 
			
		||||
3. @{number}: The X-coordinate of the click.
 | 
			
		||||
4. @{number}: The Y-coordinate of the click.
 | 
			
		||||
 | 
			
		||||
## Mouse buttons
 | 
			
		||||
Several mouse events (@{mouse_click}, @{mouse_up}, @{mouse_scroll}) contain a "mouse button" code. This takes a
 | 
			
		||||
numerical value depending on which button on your mouse was last pressed when this event occurred.
 | 
			
		||||
 | 
			
		||||
<table class="pretty-table">
 | 
			
		||||
    <!-- Our markdown parser doesn't work on tables!? Guess I'll have to roll my own soonish :/. -->
 | 
			
		||||
    <tr><th>Button code</th><th>Mouse button</th></tr>
 | 
			
		||||
    <tr><td align="right">1</td><td>Left button</td></tr>
 | 
			
		||||
    <tr><td align="right">2</td><td>Middle button</td></tr>
 | 
			
		||||
    <tr><td align="right">3</td><td>Right button</td></tr>
 | 
			
		||||
</table>
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Print the button and the coordinates whenever the mouse is clicked.
 | 
			
		||||
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, button, x, y = os.pullEvent("mouse_click")
 | 
			
		||||
  print(("The mouse button %s was pressed at %d, %d"):format(button, x, y))
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										22
									
								
								doc/events/mouse_drag.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								doc/events/mouse_drag.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] mouse_drag
 | 
			
		||||
see: mouse_click For when a mouse button is initially pressed.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
This event is fired every time the mouse is moved while a mouse button is being held.
 | 
			
		||||
 | 
			
		||||
## Return values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{number}: The [mouse button](mouse_click.html#Mouse_buttons) that is being pressed.
 | 
			
		||||
3. @{number}: The X-coordinate of the mouse.
 | 
			
		||||
4. @{number}: The Y-coordinate of the mouse.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Print the button and the coordinates whenever the mouse is dragged.
 | 
			
		||||
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, button, x, y = os.pullEvent("mouse_drag")
 | 
			
		||||
  print(("The mouse button %s was dragged at %d, %d"):format(button, x, y))
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										21
									
								
								doc/events/mouse_scroll.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								doc/events/mouse_scroll.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] mouse_scroll
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
This event is fired when a mouse wheel is scrolled in the terminal.
 | 
			
		||||
 | 
			
		||||
## Return values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{number}: The direction of the scroll. (-1 = up, 1 = down)
 | 
			
		||||
3. @{number}: The X-coordinate of the mouse when scrolling.
 | 
			
		||||
4. @{number}: The Y-coordinate of the mouse when scrolling.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints the direction of each scroll, and the position of the mouse at the time.
 | 
			
		||||
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, dir, x, y = os.pullEvent("mouse_scroll")
 | 
			
		||||
  print(("The mouse was scrolled in direction %s at %d, %d"):format(dir, x, y))
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										21
									
								
								doc/events/mouse_up.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								doc/events/mouse_up.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] mouse_up
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
This event is fired when a mouse button is released or a held mouse leaves the computer's terminal.
 | 
			
		||||
 | 
			
		||||
## Return values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{number}: The [mouse button](mouse_click.html#Mouse_buttons) that was released.
 | 
			
		||||
3. @{number}: The X-coordinate of the mouse.
 | 
			
		||||
4. @{number}: The Y-coordinate of the mouse.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints the coordinates and button number whenever the mouse is released.
 | 
			
		||||
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, button, x, y = os.pullEvent("mouse_up")
 | 
			
		||||
  print(("The mouse button %s was released at %d, %d"):format(button, x, y))
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										18
									
								
								doc/events/paste.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								doc/events/paste.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] paste
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{paste} event is fired when text is pasted into the computer through Ctrl-V (or ⌘V on Mac).
 | 
			
		||||
 | 
			
		||||
## Return values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string} The text that was pasted.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints pasted text:
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, text = os.pullEvent("paste")
 | 
			
		||||
  print('"' .. text .. '" was pasted')
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										19
									
								
								doc/events/peripheral.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								doc/events/peripheral.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] peripheral
 | 
			
		||||
see: peripheral_detach For the event fired when a peripheral is detached.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{peripheral} event is fired when a peripheral is attached on a side or to a modem.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string}: The side the peripheral was attached to.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints a message when a peripheral is attached:
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, side = os.pullEvent("peripheral")
 | 
			
		||||
  print("A peripheral was attached on side " .. side)
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										19
									
								
								doc/events/peripheral_detach.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								doc/events/peripheral_detach.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] peripheral_detach
 | 
			
		||||
see: peripheral For the event fired when a peripheral is attached.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{peripheral_detach} event is fired when a peripheral is detached from a side or from a modem.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string}: The side the peripheral was detached from.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints a message when a peripheral is detached:
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, side = os.pullEvent("peripheral_detach")
 | 
			
		||||
  print("A peripheral was detached on side " .. side)
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										30
									
								
								doc/events/rednet_message.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								doc/events/rednet_message.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] rednet_message
 | 
			
		||||
see: modem_message For raw modem messages sent outside of Rednet.
 | 
			
		||||
see: rednet.receive To wait for a Rednet message with an optional timeout and protocol filter.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{rednet_message} event is fired when a message is sent over Rednet.
 | 
			
		||||
 | 
			
		||||
This event is usually handled by @{rednet.receive}, but it can also be pulled manually.
 | 
			
		||||
 | 
			
		||||
@{rednet_message} events are sent by @{rednet.run} in the top-level coroutine in response to @{modem_message} events. A @{rednet_message} event is always preceded by a @{modem_message} event. They are generated inside CraftOS rather than being sent by the ComputerCraft machine.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{number}: The ID of the sending computer.
 | 
			
		||||
3. @{any}: The message sent.
 | 
			
		||||
4. @{string|nil}: The protocol of the message, if provided.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints a message when one is sent:
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event, sender, message, protocol = os.pullEvent("rednet_message")
 | 
			
		||||
  if protocol ~= nil then
 | 
			
		||||
    print("Received message from " .. sender .. " with protocol " .. protocol .. " and message " .. tostring(message))
 | 
			
		||||
  else
 | 
			
		||||
    print("Received message from " .. sender .. " with message " .. tostring(message))
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										14
									
								
								doc/events/redstone.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								doc/events/redstone.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] redstone
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{redstone} event is fired whenever any redstone inputs on the computer change.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints a message when a redstone input changes:
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  os.pullEvent("redstone")
 | 
			
		||||
  print("A redstone input has changed!")
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										28
									
								
								doc/events/task_complete.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								doc/events/task_complete.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] task_complete
 | 
			
		||||
see: commands.execAsync To run a command which fires a task_complete event.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{task_complete} event is fired when an asynchronous task completes. This is usually handled inside the function call that queued the task; however, functions such as @{commands.execAsync} return immediately so the user can wait for completion.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{number}: The ID of the task that completed.
 | 
			
		||||
3. @{boolean}: Whether the command succeeded.
 | 
			
		||||
4. @{string}: If the command failed, an error message explaining the failure. (This is not present if the command succeeded.)
 | 
			
		||||
...: Any parameters returned from the command.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints the results of an asynchronous command:
 | 
			
		||||
```lua
 | 
			
		||||
local taskID = commands.execAsync("say Hello")
 | 
			
		||||
local event
 | 
			
		||||
repeat
 | 
			
		||||
    event = {os.pullEvent("task_complete")}
 | 
			
		||||
until event[2] == taskID
 | 
			
		||||
if event[3] == true then
 | 
			
		||||
  print("Task " .. event[2] .. " succeeded:", table.unpack(event, 4))
 | 
			
		||||
else
 | 
			
		||||
  print("Task " .. event[2] .. " failed: " .. event[4])
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										15
									
								
								doc/events/term_resize.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								doc/events/term_resize.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] term_resize
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{term_resize} event is fired when the main terminal is resized, mainly when a new tab is opened or closed in @{multishell}.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints :
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  os.pullEvent("term_resize")
 | 
			
		||||
  local w, h = term.getSize()
 | 
			
		||||
  print("The term was resized to (" .. w .. ", " .. h .. ")")
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										25
									
								
								doc/events/terminate.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								doc/events/terminate.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] terminate
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{terminate} event is fired when <kbd>Ctrl-T</kbd> is held down.
 | 
			
		||||
 | 
			
		||||
This event is normally handled by @{os.pullEvent}, and will not be returned. However, @{os.pullEventRaw} will return this event when fired.
 | 
			
		||||
 | 
			
		||||
@{terminate} will be sent even when a filter is provided to @{os.pullEventRaw}. When using @{os.pullEventRaw} with a filter, make sure to check that the event is not @{terminate}.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints a message when Ctrl-T is held:
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  local event = os.pullEventRaw("terminate")
 | 
			
		||||
  if event == "terminate" then print("Terminate requested!") end
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Exits when Ctrl-T is held:
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  os.pullEvent()
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										21
									
								
								doc/events/timer.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								doc/events/timer.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] timer
 | 
			
		||||
see: os.startTimer To start a timer.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{timer} event is fired when a timer started with @{os.startTimer} completes.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{number}: The ID of the timer that finished.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Starts a timer and then prints its ID:
 | 
			
		||||
```lua
 | 
			
		||||
local timerID = os.startTimer(2)
 | 
			
		||||
local event, id
 | 
			
		||||
repeat
 | 
			
		||||
    event, id = os.pullEvent("timer")
 | 
			
		||||
until id == timerID
 | 
			
		||||
print("Timer with ID " .. id .. " was fired")
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										14
									
								
								doc/events/turtle_inventory.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								doc/events/turtle_inventory.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] turtle_inventory
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{turtle_inventory} event is fired when a turtle's inventory is changed.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints a message when the inventory is changed:
 | 
			
		||||
```lua
 | 
			
		||||
while true do
 | 
			
		||||
  os.pullEvent("turtle_inventory")
 | 
			
		||||
  print("The inventory was changed.")
 | 
			
		||||
end
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										21
									
								
								doc/events/websocket_closed.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								doc/events/websocket_closed.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] websocket_closed
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{websocket_closed} event is fired when an open WebSocket connection is closed.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string}: The URL of the WebSocket that was closed.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints a message when a WebSocket is closed (this may take a minute):
 | 
			
		||||
```lua
 | 
			
		||||
local myURL = "wss://example.tweaked.cc/echo"
 | 
			
		||||
local ws = http.websocket(myURL)
 | 
			
		||||
local event, url
 | 
			
		||||
repeat
 | 
			
		||||
    event, url = os.pullEvent("websocket_closed")
 | 
			
		||||
until url == myURL
 | 
			
		||||
print("The WebSocket at " .. url .. " was closed.")
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										25
									
								
								doc/events/websocket_failure.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								doc/events/websocket_failure.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] websocket_failure
 | 
			
		||||
see: http.websocketAsync To send an HTTP request.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{websocket_failure} event is fired when a WebSocket connection request fails.
 | 
			
		||||
 | 
			
		||||
This event is normally handled inside @{http.websocket}, but it can still be seen when using @{http.websocketAsync}.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string}: The URL of the site requested.
 | 
			
		||||
3. @{string}: An error describing the failure.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints an error why the website cannot be contacted:
 | 
			
		||||
```lua
 | 
			
		||||
local myURL = "wss://example.tweaked.cc/not-a-websocket"
 | 
			
		||||
http.websocketAsync(myURL)
 | 
			
		||||
local event, url, err
 | 
			
		||||
repeat
 | 
			
		||||
    event, url, err = os.pullEvent("websocket_failure")
 | 
			
		||||
until url == myURL
 | 
			
		||||
print("The URL " .. url .. " could not be reached: " .. err)
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										27
									
								
								doc/events/websocket_message.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								doc/events/websocket_message.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] websocket_message
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{websocket_message} event is fired when a message is received on an open WebSocket connection.
 | 
			
		||||
 | 
			
		||||
This event is normally handled by @{http.Websocket.receive}, but it can also be pulled manually.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string}: The URL of the WebSocket.
 | 
			
		||||
3. @{string}: The contents of the message.
 | 
			
		||||
4. @{boolean}: Whether this is a binary message.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints a message sent by a WebSocket:
 | 
			
		||||
```lua
 | 
			
		||||
local myURL = "wss://example.tweaked.cc/echo"
 | 
			
		||||
local ws = http.websocket(myURL)
 | 
			
		||||
ws.send("Hello!")
 | 
			
		||||
local event, url, message
 | 
			
		||||
repeat
 | 
			
		||||
    event, url, message = os.pullEvent("websocket_message")
 | 
			
		||||
until url == myURL
 | 
			
		||||
print("Received message from " .. url .. " with contents " .. message)
 | 
			
		||||
ws.close()
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										28
									
								
								doc/events/websocket_success.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								doc/events/websocket_success.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
---
 | 
			
		||||
module: [kind=event] websocket_success
 | 
			
		||||
see: http.websocketAsync To open a WebSocket asynchronously.
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
The @{websocket_success} event is fired when a WebSocket connection request returns successfully.
 | 
			
		||||
 | 
			
		||||
This event is normally handled inside @{http.websocket}, but it can still be seen when using @{http.websocketAsync}.
 | 
			
		||||
 | 
			
		||||
## Return Values
 | 
			
		||||
1. @{string}: The event name.
 | 
			
		||||
2. @{string}: The URL of the site.
 | 
			
		||||
3. @{http.Websocket}: The handle for the WebSocket.
 | 
			
		||||
 | 
			
		||||
## Example
 | 
			
		||||
Prints the content of a website (this may fail if the request fails):
 | 
			
		||||
```lua
 | 
			
		||||
local myURL = "wss://example.tweaked.cc/echo"
 | 
			
		||||
http.websocketAsync(myURL)
 | 
			
		||||
local event, url, handle
 | 
			
		||||
repeat
 | 
			
		||||
    event, url, handle = os.pullEvent("websocket_success")
 | 
			
		||||
until url == myURL
 | 
			
		||||
print("Connected to " .. url)
 | 
			
		||||
handle.send("Hello!")
 | 
			
		||||
print(handle.receive())
 | 
			
		||||
handle.close()
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										1
									
								
								doc/head.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								doc/head.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
<meta name="theme-color" content="#c8d87c">
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								doc/images/basic-terminal.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								doc/images/basic-terminal.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 53 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								doc/images/peripherals.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								doc/images/peripherals.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 194 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								doc/images/turtle.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								doc/images/turtle.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 163 KiB  | 
							
								
								
									
										55
									
								
								doc/index.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								doc/index.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,55 @@
 | 
			
		||||
# 
 | 
			
		||||
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 better performance, stability, and a wealth of new features.
 | 
			
		||||
 | 
			
		||||
CC: Tweaked can be installed from [CurseForge] or [Modrinth]. It requires the [Minecraft Forge][forge] mod loader, but
 | 
			
		||||
[versions are available for Fabric][ccrestitched].
 | 
			
		||||
 | 
			
		||||
## Features
 | 
			
		||||
Controlled using the [Lua programming language][lua], CC: Tweaked's computers provides all the tools you need to start
 | 
			
		||||
writing code and automating your Minecraft world.
 | 
			
		||||
 | 
			
		||||
{.big-image}
 | 
			
		||||
 | 
			
		||||
While computers are incredibly powerful, they're rather limited by their inability to move about. *Turtles* are the
 | 
			
		||||
solution here. They can move about the world, placing and breaking blocks, swinging a sword to protect you from zombies,
 | 
			
		||||
or whatever else you program them to!
 | 
			
		||||
 | 
			
		||||
{.big-image}
 | 
			
		||||
 | 
			
		||||
Not all problems can be solved with a pickaxe though, and so CC: Tweaked also provides a bunch of additional peripherals
 | 
			
		||||
for your computers. You can play a tune with speakers, display text or images on a monitor, connect all your
 | 
			
		||||
computers together with modems, and much more.
 | 
			
		||||
 | 
			
		||||
Computers can now also interact with inventories such as chests, allowing you to build complex inventory and item
 | 
			
		||||
management systems.
 | 
			
		||||
 | 
			
		||||
{.big-image}
 | 
			
		||||
 | 
			
		||||
## Getting Started
 | 
			
		||||
While ComputerCraft is lovely for both experienced programmers and for people who have never coded before, it can be a
 | 
			
		||||
little daunting getting started. Thankfully, there's several fantastic tutorials out there:
 | 
			
		||||
 | 
			
		||||
 - [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")
 | 
			
		||||
 | 
			
		||||
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 pop in to the [Minecraft Computer Mod Discord guild][discord] or ComputerCraft's
 | 
			
		||||
[IRC channel][irc].
 | 
			
		||||
 | 
			
		||||
## Get Involved
 | 
			
		||||
CC: Tweaked lives on [GitHub]. If you've got any ideas, feedback or bugs please do [create an issue][bug].
 | 
			
		||||
 | 
			
		||||
[github]: https://github.com/cc-tweaked/CC-Tweaked/ "CC: Tweaked on GitHub"
 | 
			
		||||
[bug]: https://github.com/cc-tweaked/CC-Tweaked/issues/new/choose
 | 
			
		||||
[computercraft]: https://github.com/dan200/ComputerCraft "ComputerCraft on GitHub"
 | 
			
		||||
[curseforge]: https://minecraft.curseforge.com/projects/cc-tweaked "Download CC: Tweaked from CurseForge"
 | 
			
		||||
[modrinth]: https://modrinth.com/mod/gu7yAYhd "Download CC: Tweaked from Modrinth"
 | 
			
		||||
[forge]: https://files.minecraftforge.net/ "Download Minecraft Forge."
 | 
			
		||||
[ccrestitched]: https://www.curseforge.com/minecraft/mc-mods/cc-restitched "Download CC: Restitched from CurseForge"
 | 
			
		||||
[lua]: https://www.lua.org/ "Lua's main website"
 | 
			
		||||
[discord]: https://discord.computercraft.cc "The Minecraft Computer Mods Discord"
 | 
			
		||||
[irc]: http://webchat.esper.net/?channels=computercraft "IRC webchat on EsperNet"
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								doc/logo.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								doc/logo.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 1.5 KiB  | 
							
								
								
									
										36
									
								
								doc/stub/fs.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								doc/stub/fs.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
---  The FS API allows you to manipulate files and the filesystem.
 | 
			
		||||
--
 | 
			
		||||
-- @module fs
 | 
			
		||||
 | 
			
		||||
--- Returns true if a path is mounted to the parent filesystem.
 | 
			
		||||
--
 | 
			
		||||
-- The root filesystem "/" is considered a mount, along with disk folders and
 | 
			
		||||
-- the rom folder. Other programs (such as network shares) can exstend this to
 | 
			
		||||
-- make other mount types by correctly assigning their return value for getDrive.
 | 
			
		||||
--
 | 
			
		||||
-- @tparam string path The path to check.
 | 
			
		||||
-- @treturn boolean If the path is mounted, rather than a normal file/folder.
 | 
			
		||||
-- @throws If the path does not exist.
 | 
			
		||||
-- @see getDrive
 | 
			
		||||
-- @since 1.87.0
 | 
			
		||||
function isDriveRoot(path) end
 | 
			
		||||
 | 
			
		||||
--[[- Provides completion for a file or directory name, suitable for use with
 | 
			
		||||
@{_G.read}.
 | 
			
		||||
 | 
			
		||||
When a directory is a possible candidate for completion, two entries are
 | 
			
		||||
included - one with a trailing slash (indicating that entries within this
 | 
			
		||||
directory exist) and one without it (meaning this entry is an immediate
 | 
			
		||||
completion candidate). `include_dirs` can be set to @{false} to only include
 | 
			
		||||
those with a trailing slash.
 | 
			
		||||
 | 
			
		||||
@tparam string path The path to complete.
 | 
			
		||||
@tparam string location The location where paths are resolved from.
 | 
			
		||||
@tparam[opt] boolean include_files When @{false}, only directories will be
 | 
			
		||||
included in the returned list.
 | 
			
		||||
@tparam[opt] boolean include_dirs When @{false}, "raw" directories will not be
 | 
			
		||||
included in the returned list.
 | 
			
		||||
@treturn { string... } A list of possible completion candidates.
 | 
			
		||||
@since 1.74
 | 
			
		||||
]]
 | 
			
		||||
function complete(path, location, include_files, include_dirs) end
 | 
			
		||||
							
								
								
									
										130
									
								
								doc/stub/global.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										130
									
								
								doc/stub/global.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,130 @@
 | 
			
		||||
--[[-
 | 
			
		||||
Functions in the global environment, defined in `bios.lua`. This does not
 | 
			
		||||
include standard Lua functions.
 | 
			
		||||
 | 
			
		||||
@module _G
 | 
			
		||||
]]
 | 
			
		||||
 | 
			
		||||
--[[- Pauses execution for the specified number of seconds.
 | 
			
		||||
 | 
			
		||||
As it waits for a fixed amount of world ticks, `time` will automatically be
 | 
			
		||||
rounded up to the nearest multiple of 0.05 seconds. If you are using coroutines
 | 
			
		||||
or the @{parallel|parallel API}, it will only pause execution of the current
 | 
			
		||||
thread, not the whole program.
 | 
			
		||||
 | 
			
		||||
**Note** Because sleep internally uses timers, it is a function that yields.
 | 
			
		||||
This means that you can use it to prevent "Too long without yielding" errors,
 | 
			
		||||
however, as the minimum sleep time is 0.05 seconds, it will slow your program
 | 
			
		||||
down.
 | 
			
		||||
 | 
			
		||||
**Warning** Internally, this function queues and waits for a timer event (using
 | 
			
		||||
@{os.startTimer}), however it does not listen for any other events. This means
 | 
			
		||||
that any event that occurs while sleeping will be entirely discarded. If you
 | 
			
		||||
need to receive events while sleeping, consider using @{os.startTimer|timers},
 | 
			
		||||
or the @{parallel|parallel API}.
 | 
			
		||||
 | 
			
		||||
@tparam number time The number of seconds to sleep for, rounded up to the
 | 
			
		||||
nearest multiple of 0.05.
 | 
			
		||||
 | 
			
		||||
@see os.startTimer
 | 
			
		||||
@usage Sleep for three seconds.
 | 
			
		||||
 | 
			
		||||
    print("Sleeping for three seconds")
 | 
			
		||||
    sleep(3)
 | 
			
		||||
    print("Done!")
 | 
			
		||||
]]
 | 
			
		||||
function sleep(time) end
 | 
			
		||||
 | 
			
		||||
--- Writes a line of text to the screen without a newline at the end, wrapping
 | 
			
		||||
-- text if necessary.
 | 
			
		||||
--
 | 
			
		||||
-- @tparam string text The text to write to the string
 | 
			
		||||
-- @treturn number The number of lines written
 | 
			
		||||
-- @see print A wrapper around write that adds a newline and accepts multiple arguments
 | 
			
		||||
-- @usage write("Hello, world")
 | 
			
		||||
function write(text) end
 | 
			
		||||
 | 
			
		||||
--- Prints the specified values to the screen separated by spaces, wrapping if
 | 
			
		||||
-- necessary. After printing, the cursor is moved to the next line.
 | 
			
		||||
--
 | 
			
		||||
-- @param ... The values to print on the screen
 | 
			
		||||
-- @treturn number The number of lines written
 | 
			
		||||
-- @usage print("Hello, world!")
 | 
			
		||||
function print(...) end
 | 
			
		||||
 | 
			
		||||
--- Prints the specified values to the screen in red, separated by spaces,
 | 
			
		||||
-- wrapping if necessary. After printing, the cursor is moved to the next line.
 | 
			
		||||
--
 | 
			
		||||
-- @param ... The values to print on the screen
 | 
			
		||||
-- @usage printError("Something went wrong!")
 | 
			
		||||
function printError(...) end
 | 
			
		||||
 | 
			
		||||
--[[- Reads user input from the terminal, automatically handling arrow keys,
 | 
			
		||||
pasting, character replacement, history scrollback, auto-completion, and
 | 
			
		||||
default values.
 | 
			
		||||
 | 
			
		||||
@tparam[opt] string replaceChar A character to replace each typed character with.
 | 
			
		||||
This can be used for hiding passwords, for example.
 | 
			
		||||
@tparam[opt] table history A table holding history items that can be scrolled
 | 
			
		||||
back to with the up/down arrow keys. The oldest item is at index 1, while the
 | 
			
		||||
newest item is at the highest index.
 | 
			
		||||
@tparam[opt] function(partial: string):({ string... }|nil) completeFn A function
 | 
			
		||||
to be used for completion. This function should take the partial text typed so
 | 
			
		||||
far, and returns a list of possible completion options.
 | 
			
		||||
@tparam[opt] string default Default text which should already be entered into
 | 
			
		||||
the prompt.
 | 
			
		||||
 | 
			
		||||
@treturn string The text typed in.
 | 
			
		||||
 | 
			
		||||
@see cc.completion For functions to help with completion.
 | 
			
		||||
@usage Read a string and echo it back to the user
 | 
			
		||||
 | 
			
		||||
    write("> ")
 | 
			
		||||
    local msg = read()
 | 
			
		||||
    print(msg)
 | 
			
		||||
 | 
			
		||||
@usage Prompt a user for a password.
 | 
			
		||||
 | 
			
		||||
    while true do
 | 
			
		||||
      write("Password> ")
 | 
			
		||||
      local pwd = read("*")
 | 
			
		||||
      if pwd == "let me in" then break end
 | 
			
		||||
      print("Incorrect password, try again.")
 | 
			
		||||
    end
 | 
			
		||||
    print("Logged in!")
 | 
			
		||||
 | 
			
		||||
@usage A complete example with completion, history and a default value.
 | 
			
		||||
 | 
			
		||||
    local completion = require "cc.completion"
 | 
			
		||||
    local history = { "potato", "orange", "apple" }
 | 
			
		||||
    local choices = { "apple", "orange", "banana", "strawberry" }
 | 
			
		||||
    write("> ")
 | 
			
		||||
    local msg = read(nil, history, function(text) return completion.choice(text, choices) end, "app")
 | 
			
		||||
    print(msg)
 | 
			
		||||
 | 
			
		||||
@changed 1.74 Added `completeFn` parameter.
 | 
			
		||||
@changed 1.80pr1 Added `default` parameter.
 | 
			
		||||
]]
 | 
			
		||||
function read(replaceChar, history, completeFn, default) end
 | 
			
		||||
 | 
			
		||||
--- The ComputerCraft and Minecraft version of the current computer environment.
 | 
			
		||||
--
 | 
			
		||||
-- For example, `ComputerCraft 1.93.0 (Minecraft 1.15.2)`.
 | 
			
		||||
-- @usage _HOST
 | 
			
		||||
-- @since 1.76
 | 
			
		||||
_HOST = _HOST
 | 
			
		||||
 | 
			
		||||
--[[- The default computer settings as defined in the ComputerCraft
 | 
			
		||||
configuration.
 | 
			
		||||
 | 
			
		||||
This is a comma-separated list of settings pairs defined by the mod
 | 
			
		||||
configuration or server owner. By default, it is empty.
 | 
			
		||||
 | 
			
		||||
An example value to disable autocompletion:
 | 
			
		||||
 | 
			
		||||
    shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false
 | 
			
		||||
 | 
			
		||||
@usage _CC_DEFAULT_SETTINGS
 | 
			
		||||
@since 1.77
 | 
			
		||||
]]
 | 
			
		||||
_CC_DEFAULT_SETTINGS = _CC_DEFAULT_SETTINGS
 | 
			
		||||
							
								
								
									
										181
									
								
								doc/stub/http.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										181
									
								
								doc/stub/http.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,181 @@
 | 
			
		||||
--- The http library allows communicating with web servers, sending and
 | 
			
		||||
-- receiving data from them.
 | 
			
		||||
--
 | 
			
		||||
-- @module http
 | 
			
		||||
-- @since 1.1
 | 
			
		||||
 | 
			
		||||
--- Asynchronously make a HTTP request to the given url.
 | 
			
		||||
--
 | 
			
		||||
-- This returns immediately, a [`http_success`](#http-success-event) or
 | 
			
		||||
-- [`http_failure`](#http-failure-event) will be queued once the request has
 | 
			
		||||
-- completed.
 | 
			
		||||
--
 | 
			
		||||
-- @tparam      string url   The url to request
 | 
			
		||||
-- @tparam[opt] string body  An optional string containing the body of the
 | 
			
		||||
-- request. If specified, a `POST` request will be made instead.
 | 
			
		||||
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
 | 
			
		||||
-- of this request.
 | 
			
		||||
-- @tparam[opt] boolean binary Whether to make a binary HTTP request. If true,
 | 
			
		||||
-- the body will not be UTF-8 encoded, and the received response will not be
 | 
			
		||||
-- decoded.
 | 
			
		||||
--
 | 
			
		||||
-- @tparam[2] {
 | 
			
		||||
--   url = string, body? = string, headers? = { [string] = string },
 | 
			
		||||
--   binary? = boolean, method? = string, redirect? = boolean,
 | 
			
		||||
-- } request Options for the request.
 | 
			
		||||
--
 | 
			
		||||
-- This table form is an expanded version of the previous syntax. All arguments
 | 
			
		||||
-- from above are passed in as fields instead (for instance,
 | 
			
		||||
-- `http.request("https://example.com")` becomes `http.request { url =
 | 
			
		||||
-- "https://example.com" }`).
 | 
			
		||||
--
 | 
			
		||||
-- This table also accepts several additional options:
 | 
			
		||||
--
 | 
			
		||||
--  - `method`: Which HTTP method to use, for instance `"PATCH"` or `"DELETE"`.
 | 
			
		||||
--  - `redirect`: Whether to follow HTTP redirects. Defaults to true.
 | 
			
		||||
--
 | 
			
		||||
-- @see http.get  For a synchronous way to make GET requests.
 | 
			
		||||
-- @see http.post For a synchronous way to make POST requests.
 | 
			
		||||
--
 | 
			
		||||
-- @changed 1.63 Added argument for headers.
 | 
			
		||||
-- @changed 1.80pr1 Added argument for binary handles.
 | 
			
		||||
-- @changed 1.80pr1.6 Added support for table argument.
 | 
			
		||||
-- @changed 1.86.0 Added PATCH and TRACE methods.
 | 
			
		||||
function request(...) end
 | 
			
		||||
 | 
			
		||||
--- Make a HTTP GET request to the given url.
 | 
			
		||||
--
 | 
			
		||||
-- @tparam string url   The url to request
 | 
			
		||||
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
 | 
			
		||||
-- of this request.
 | 
			
		||||
-- @tparam[opt] boolean binary Whether to make a binary HTTP request. If true,
 | 
			
		||||
-- the body will not be UTF-8 encoded, and the received response will not be
 | 
			
		||||
-- decoded.
 | 
			
		||||
--
 | 
			
		||||
-- @tparam[2] {
 | 
			
		||||
--   url = string, headers? = { [string] = string },
 | 
			
		||||
--   binary? = boolean, method? = string, redirect? = boolean,
 | 
			
		||||
-- } request Options for the request. See @{http.request} for details on how
 | 
			
		||||
-- these options behave.
 | 
			
		||||
--
 | 
			
		||||
-- @treturn Response The resulting http response, which can be read from.
 | 
			
		||||
-- @treturn[2] nil When the http request failed, such as in the event of a 404
 | 
			
		||||
-- error or connection timeout.
 | 
			
		||||
-- @treturn string A message detailing why the request failed.
 | 
			
		||||
-- @treturn Response|nil The failing http response, if available.
 | 
			
		||||
--
 | 
			
		||||
-- @changed 1.63 Added argument for headers.
 | 
			
		||||
-- @changed 1.80pr1 Response handles are now returned on error if available.
 | 
			
		||||
-- @changed 1.80pr1 Added argument for binary handles.
 | 
			
		||||
-- @changed 1.80pr1.6 Added support for table argument.
 | 
			
		||||
-- @changed 1.86.0 Added PATCH and TRACE methods.
 | 
			
		||||
--
 | 
			
		||||
-- @usage Make a request to [example.tweaked.cc](https://example.tweaked.cc),
 | 
			
		||||
-- and print the returned page.
 | 
			
		||||
-- ```lua
 | 
			
		||||
-- local request = http.get("https://example.tweaked.cc")
 | 
			
		||||
-- print(request.readAll())
 | 
			
		||||
-- -- => HTTP is working!
 | 
			
		||||
-- request.close()
 | 
			
		||||
-- ```
 | 
			
		||||
function get(...) end
 | 
			
		||||
 | 
			
		||||
--- Make a HTTP POST request to the given url.
 | 
			
		||||
--
 | 
			
		||||
-- @tparam string url   The url to request
 | 
			
		||||
-- @tparam string body  The body of the POST request.
 | 
			
		||||
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
 | 
			
		||||
-- of this request.
 | 
			
		||||
-- @tparam[opt] boolean binary Whether to make a binary HTTP request. If true,
 | 
			
		||||
-- the body will not be UTF-8 encoded, and the received response will not be
 | 
			
		||||
-- decoded.
 | 
			
		||||
--
 | 
			
		||||
-- @tparam[2] {
 | 
			
		||||
--   url = string, body? = string, headers? = { [string] = string },
 | 
			
		||||
--   binary? = boolean, method? = string, redirect? = boolean,
 | 
			
		||||
-- } request Options for the request. See @{http.request} for details on how
 | 
			
		||||
-- these options behave.
 | 
			
		||||
--
 | 
			
		||||
-- @treturn Response The resulting http response, which can be read from.
 | 
			
		||||
-- @treturn[2] nil When the http request failed, such as in the event of a 404
 | 
			
		||||
-- error or connection timeout.
 | 
			
		||||
-- @treturn string A message detailing why the request failed.
 | 
			
		||||
-- @treturn Response|nil The failing http response, if available.
 | 
			
		||||
--
 | 
			
		||||
-- @since 1.31
 | 
			
		||||
-- @changed 1.63 Added argument for headers.
 | 
			
		||||
-- @changed 1.80pr1 Response handles are now returned on error if available.
 | 
			
		||||
-- @changed 1.80pr1 Added argument for binary handles.
 | 
			
		||||
-- @changed 1.80pr1.6 Added support for table argument.
 | 
			
		||||
-- @changed 1.86.0 Added PATCH and TRACE methods.
 | 
			
		||||
function post(...) end
 | 
			
		||||
 | 
			
		||||
--- Asynchronously determine whether a URL can be requested.
 | 
			
		||||
--
 | 
			
		||||
-- If this returns `true`, one should also listen for [`http_check`
 | 
			
		||||
-- events](#http-check-event) which will container further information about
 | 
			
		||||
-- whether the URL is allowed or not.
 | 
			
		||||
--
 | 
			
		||||
-- @tparam string url The URL to check.
 | 
			
		||||
-- @treturn true When this url is not invalid. This does not imply that it is
 | 
			
		||||
-- allowed - see the comment above.
 | 
			
		||||
-- @treturn[2] false When this url is invalid.
 | 
			
		||||
-- @treturn string A reason why this URL is not valid (for instance, if it is
 | 
			
		||||
-- malformed, or blocked).
 | 
			
		||||
--
 | 
			
		||||
-- @see http.checkURL For a synchronous version.
 | 
			
		||||
function checkURLAsync(url) end
 | 
			
		||||
 | 
			
		||||
--- Determine whether a URL can be requested.
 | 
			
		||||
--
 | 
			
		||||
-- If this returns `true`, one should also listen for [`http_check`
 | 
			
		||||
-- events](#http-check-event) which will container further information about
 | 
			
		||||
-- whether the URL is allowed or not.
 | 
			
		||||
--
 | 
			
		||||
-- @tparam string url The URL to check.
 | 
			
		||||
-- @treturn true When this url is valid and can be requested via @{http.request}.
 | 
			
		||||
-- @treturn[2] false When this url is invalid.
 | 
			
		||||
-- @treturn string A reason why this URL is not valid (for instance, if it is
 | 
			
		||||
-- malformed, or blocked).
 | 
			
		||||
--
 | 
			
		||||
-- @see http.checkURLAsync For an asynchronous version.
 | 
			
		||||
--
 | 
			
		||||
-- @usage
 | 
			
		||||
-- ```lua
 | 
			
		||||
-- print(http.checkURL("https://example.tweaked.cc/"))
 | 
			
		||||
-- -- => true
 | 
			
		||||
-- print(http.checkURL("http://localhost/"))
 | 
			
		||||
-- -- => false Domain not permitted
 | 
			
		||||
-- print(http.checkURL("not a url"))
 | 
			
		||||
-- -- => false URL malformed
 | 
			
		||||
-- ```
 | 
			
		||||
function checkURL(url) end
 | 
			
		||||
 | 
			
		||||
--- Open a websocket.
 | 
			
		||||
--
 | 
			
		||||
-- @tparam string url The websocket url to connect to. This should have the
 | 
			
		||||
-- `ws://` or `wss://` protocol.
 | 
			
		||||
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
 | 
			
		||||
-- of the initial websocket connection.
 | 
			
		||||
--
 | 
			
		||||
-- @treturn Websocket The websocket connection.
 | 
			
		||||
-- @treturn[2] false If the websocket connection failed.
 | 
			
		||||
-- @treturn string An error message describing why the connection failed.
 | 
			
		||||
-- @since 1.80pr1.1
 | 
			
		||||
-- @changed 1.80pr1.3 No longer asynchronous.
 | 
			
		||||
-- @changed 1.95.3 Added User-Agent to default headers.
 | 
			
		||||
function websocket(url, headers) end
 | 
			
		||||
 | 
			
		||||
--- Asynchronously open a websocket.
 | 
			
		||||
--
 | 
			
		||||
-- This returns immediately, a [`websocket_success`](#websocket-success-event)
 | 
			
		||||
-- or [`websocket_failure`](#websocket-failure-event) will be queued once the
 | 
			
		||||
-- request has completed.
 | 
			
		||||
--
 | 
			
		||||
-- @tparam string url The websocket url to connect to. This should have the
 | 
			
		||||
-- `ws://` or `wss://` protocol.
 | 
			
		||||
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
 | 
			
		||||
-- of the initial websocket connection.
 | 
			
		||||
-- @since 1.80pr1.3
 | 
			
		||||
-- @changed 1.95.3 Added User-Agent to default headers.
 | 
			
		||||
function websocketAsync(url, headers) end
 | 
			
		||||
							
								
								
									
										128
									
								
								doc/stub/os.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										128
									
								
								doc/stub/os.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,128 @@
 | 
			
		||||
-- Defined in bios.lua
 | 
			
		||||
 | 
			
		||||
--[[- Loads the given API into the global environment.
 | 
			
		||||
 | 
			
		||||
This function loads and executes the file at the given path, and all global
 | 
			
		||||
variables and functions exported by it will by available through the use of
 | 
			
		||||
`myAPI.<function name>`, where `myAPI` is the base name of the API file.
 | 
			
		||||
 | 
			
		||||
@tparam string path The path of the API to load.
 | 
			
		||||
@treturn boolean Whether or not the API was successfully loaded.
 | 
			
		||||
@since 1.2
 | 
			
		||||
 | 
			
		||||
@deprecated When possible it's best to avoid using this function. It pollutes
 | 
			
		||||
the global table and can mask errors.
 | 
			
		||||
 | 
			
		||||
@{require} should be used to load libraries instead.
 | 
			
		||||
]]
 | 
			
		||||
function loadAPI(path) end
 | 
			
		||||
 | 
			
		||||
--- Unloads an API which was loaded by @{os.loadAPI}.
 | 
			
		||||
--
 | 
			
		||||
-- This effectively removes the specified table from `_G`.
 | 
			
		||||
--
 | 
			
		||||
-- @tparam string name The name of the API to unload.
 | 
			
		||||
-- @since 1.2
 | 
			
		||||
-- @deprecated See @{os.loadAPI} for why.
 | 
			
		||||
function unloadAPI(name) end
 | 
			
		||||
 | 
			
		||||
--[[- Pause execution of the current thread and waits for any events matching
 | 
			
		||||
`filter`.
 | 
			
		||||
 | 
			
		||||
This function @{coroutine.yield|yields} the current process and waits for it
 | 
			
		||||
to be resumed with a vararg list where the first element matches `filter`.
 | 
			
		||||
If no `filter` is supplied, this will match all events.
 | 
			
		||||
 | 
			
		||||
Unlike @{os.pullEventRaw}, it will stop the application upon a "terminate"
 | 
			
		||||
event, printing the error "Terminated".
 | 
			
		||||
 | 
			
		||||
@tparam[opt] string filter Event to filter for.
 | 
			
		||||
@treturn string event The name of the event that fired.
 | 
			
		||||
@treturn any param... Optional additional parameters of the event.
 | 
			
		||||
@usage Listen for `mouse_click` events.
 | 
			
		||||
 | 
			
		||||
    while true do
 | 
			
		||||
        local event, button, x, y = os.pullEvent("mouse_click")
 | 
			
		||||
        print("Button", button, "was clicked at", x, ",", y)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@usage Listen for multiple events.
 | 
			
		||||
 | 
			
		||||
    while true do
 | 
			
		||||
        local eventData = {os.pullEvent()}
 | 
			
		||||
        local event = eventData[1]
 | 
			
		||||
 | 
			
		||||
        if event == "mouse_click" then
 | 
			
		||||
            print("Button", eventData[2], "was clicked at", eventData[3], ",", eventData[4])
 | 
			
		||||
        elseif event == "key" then
 | 
			
		||||
            print("Key code", eventData[2], "was pressed")
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@see os.pullEventRaw To pull the terminate event.
 | 
			
		||||
@changed 1.3 Added filter argument.
 | 
			
		||||
]]
 | 
			
		||||
function pullEvent(filter) end
 | 
			
		||||
 | 
			
		||||
--[[- Pause execution of the current thread and waits for events, including the
 | 
			
		||||
`terminate` event.
 | 
			
		||||
 | 
			
		||||
This behaves almost the same as @{os.pullEvent}, except it allows you to handle
 | 
			
		||||
the `terminate` event yourself - the program will not stop execution when
 | 
			
		||||
<kbd>Ctrl+T</kbd> is pressed.
 | 
			
		||||
 | 
			
		||||
@tparam[opt] string filter Event to filter for.
 | 
			
		||||
@treturn string event The name of the event that fired.
 | 
			
		||||
@treturn any param... Optional additional parameters of the event.
 | 
			
		||||
@usage Listen for `terminate` events.
 | 
			
		||||
 | 
			
		||||
    while true do
 | 
			
		||||
        local event = os.pullEventRaw()
 | 
			
		||||
        if event == "terminate" then
 | 
			
		||||
            print("Caught terminate event!")
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@see os.pullEvent To pull events normally.
 | 
			
		||||
]]
 | 
			
		||||
function pullEventRaw(filter) end
 | 
			
		||||
 | 
			
		||||
--- Pauses execution for the specified number of seconds, alias of @{_G.sleep}.
 | 
			
		||||
--
 | 
			
		||||
-- @tparam number time The number of seconds to sleep for, rounded up to the
 | 
			
		||||
-- nearest multiple of 0.05.
 | 
			
		||||
function sleep(time) end
 | 
			
		||||
 | 
			
		||||
--- Get the current CraftOS version (for example, `CraftOS 1.8`).
 | 
			
		||||
--
 | 
			
		||||
-- This is defined by `bios.lua`. For the current version of CC:Tweaked, this
 | 
			
		||||
-- should return `CraftOS 1.8`.
 | 
			
		||||
--
 | 
			
		||||
-- @treturn string The current CraftOS version.
 | 
			
		||||
-- @usage os.version()
 | 
			
		||||
function version() end
 | 
			
		||||
 | 
			
		||||
--[[- Run the program at the given path with the specified environment and
 | 
			
		||||
arguments.
 | 
			
		||||
 | 
			
		||||
This function does not resolve program names like the shell does. This means
 | 
			
		||||
that, for example, `os.run("edit")` will not work. As well as this, it does not
 | 
			
		||||
provide access to the @{shell} API in the environment. For this behaviour, use
 | 
			
		||||
@{shell.run} instead.
 | 
			
		||||
 | 
			
		||||
If the program cannot be found, or failed to run, it will print the error and
 | 
			
		||||
return `false`. If you want to handle this more gracefully, use an alternative
 | 
			
		||||
such as @{loadfile}.
 | 
			
		||||
 | 
			
		||||
@tparam table env The environment to run the program with.
 | 
			
		||||
@tparam string path The exact path of the program to run.
 | 
			
		||||
@param ... The arguments to pass to the program.
 | 
			
		||||
@treturn boolean Whether or not the program ran successfully.
 | 
			
		||||
@usage Run the default shell from within your program:
 | 
			
		||||
 | 
			
		||||
    os.run({}, "/rom/programs/shell.lua")
 | 
			
		||||
 | 
			
		||||
@see shell.run
 | 
			
		||||
@see loadfile
 | 
			
		||||
]]
 | 
			
		||||
function run(env, path, ...) end
 | 
			
		||||
							
								
								
									
										14
									
								
								doc/stub/turtle.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								doc/stub/turtle.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
--[[- Craft a recipe based on the turtle's inventory.
 | 
			
		||||
 | 
			
		||||
The turtle's inventory should set up like a crafting grid. For instance, to
 | 
			
		||||
craft sticks, slots 1 and 5 should contain planks. _All_ other slots should be
 | 
			
		||||
empty, including those outside the crafting "grid".
 | 
			
		||||
 | 
			
		||||
@tparam[opt=64] number limit The maximum number of crafting steps to run.
 | 
			
		||||
@throws When limit is less than 1 or greater than 64.
 | 
			
		||||
@treturn[1] true If crafting succeeds.
 | 
			
		||||
@treturn[2] false If crafting fails.
 | 
			
		||||
@treturn string A string describing why crafting failed.
 | 
			
		||||
@since 1.4
 | 
			
		||||
]]
 | 
			
		||||
function craft(limit) end
 | 
			
		||||
@@ -2,16 +2,14 @@
 | 
			
		||||
org.gradle.jvmargs=-Xmx1G
 | 
			
		||||
 | 
			
		||||
# Mod properties
 | 
			
		||||
mod_version=1.96.1-beta
 | 
			
		||||
mod_version=1.97.5
 | 
			
		||||
 | 
			
		||||
# Minecraft properties
 | 
			
		||||
mc_version=1.16.5
 | 
			
		||||
mappings_version=9
 | 
			
		||||
mc_version=1.17.1
 | 
			
		||||
fabric_api_version=0.40.1+1.17
 | 
			
		||||
fabric_loader_version=0.12.0
 | 
			
		||||
 | 
			
		||||
# Dependencies
 | 
			
		||||
cloth_config_version=4.11.26
 | 
			
		||||
fabric_loader_version=0.11.3
 | 
			
		||||
fabric_api_version=0.32.0+1.16
 | 
			
		||||
cloth_api_version=2.0.54
 | 
			
		||||
cloth_config_version=5.0.34
 | 
			
		||||
jankson_version=1.2.0
 | 
			
		||||
modmenu_version=1.16.9
 | 
			
		||||
cloth_api_version=1.4.5
 | 
			
		||||
modmenu_version=2.0.2
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							@@ -1,5 +1,5 @@
 | 
			
		||||
distributionBase=GRADLE_USER_HOME
 | 
			
		||||
distributionPath=wrapper/dists
 | 
			
		||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
 | 
			
		||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
 | 
			
		||||
zipStoreBase=GRADLE_USER_HOME
 | 
			
		||||
zipStorePath=wrapper/dists
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										115
									
								
								illuaminate.sexp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										115
									
								
								illuaminate.sexp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,115 @@
 | 
			
		||||
; -*- mode: Lisp;-*-
 | 
			
		||||
 | 
			
		||||
(sources
 | 
			
		||||
  /doc/stub/
 | 
			
		||||
  /doc/events/
 | 
			
		||||
  /build/docs/luaJavadoc/
 | 
			
		||||
  /src/main/resources/*/computercraft/lua/bios.lua
 | 
			
		||||
  /src/main/resources/*/computercraft/lua/rom/
 | 
			
		||||
  /src/test/resources/test-rom
 | 
			
		||||
  /src/web/mount)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
(doc
 | 
			
		||||
  (destination build/docs/lua)
 | 
			
		||||
  (index doc/index.md)
 | 
			
		||||
 | 
			
		||||
  (site
 | 
			
		||||
    (title "CC: Tweaked")
 | 
			
		||||
    (logo src/main/resources/pack.png)
 | 
			
		||||
    (url https://tweaked.cc/)
 | 
			
		||||
    (source-link https://github.com/cc-tweaked/CC-Tweaked/blob/${commit}/${path}#L${line})
 | 
			
		||||
 | 
			
		||||
    (styles src/web/styles.css)
 | 
			
		||||
    (scripts build/rollup/index.js)
 | 
			
		||||
    (head doc/head.html))
 | 
			
		||||
 | 
			
		||||
  (module-kinds
 | 
			
		||||
    (peripheral Peripherals)
 | 
			
		||||
    (generic_peripheral "Generic Peripherals")
 | 
			
		||||
    (event Events))
 | 
			
		||||
 | 
			
		||||
  (library-path
 | 
			
		||||
    /doc/stub/
 | 
			
		||||
    /build/docs/luaJavadoc/
 | 
			
		||||
 | 
			
		||||
    /src/main/resources/*/computercraft/lua/rom/apis/
 | 
			
		||||
    /src/main/resources/*/computercraft/lua/rom/apis/command/
 | 
			
		||||
    /src/main/resources/*/computercraft/lua/rom/apis/turtle/
 | 
			
		||||
 | 
			
		||||
    /src/main/resources/*/computercraft/lua/rom/modules/main/
 | 
			
		||||
    /src/main/resources/*/computercraft/lua/rom/modules/command/
 | 
			
		||||
    /src/main/resources/*/computercraft/lua/rom/modules/turtle/))
 | 
			
		||||
 | 
			
		||||
(at /
 | 
			
		||||
  (linters
 | 
			
		||||
    syntax:string-index
 | 
			
		||||
 | 
			
		||||
    ;; It'd be nice to avoid this, but right now there's a lot of instances of
 | 
			
		||||
    ;; it.
 | 
			
		||||
    -var:set-loop
 | 
			
		||||
 | 
			
		||||
    ;; It's useful to name arguments for documentation, so we allow this. It'd
 | 
			
		||||
    ;; be good to find a compromise in the future, but this works for now.
 | 
			
		||||
    -var:unused-arg)
 | 
			
		||||
 | 
			
		||||
  (lint
 | 
			
		||||
    (bracket-spaces
 | 
			
		||||
      (call no-space)
 | 
			
		||||
      (function-args no-space)
 | 
			
		||||
      (parens no-space)
 | 
			
		||||
      (table space)
 | 
			
		||||
      (index no-space))
 | 
			
		||||
 | 
			
		||||
    (allow-clarifying-parens true)
 | 
			
		||||
 | 
			
		||||
    ;; colours imports from colors, and we don't handle that right now.
 | 
			
		||||
    ;; keys is entirely dynamic, so we skip it.
 | 
			
		||||
    (dynamic-modules colours keys _G)
 | 
			
		||||
 | 
			
		||||
    (globals
 | 
			
		||||
      :max
 | 
			
		||||
      _CC_DEFAULT_SETTINGS
 | 
			
		||||
      _CC_DISABLE_LUA51_FEATURES
 | 
			
		||||
      _HOST
 | 
			
		||||
      ;; Ideally we'd pick these up from bios.lua, but illuaminate currently
 | 
			
		||||
      ;; isn't smart enough.
 | 
			
		||||
      sleep write printError read rs)))
 | 
			
		||||
 | 
			
		||||
;; We disable the unused global linter in bios.lua and the APIs. In the future
 | 
			
		||||
;; hopefully we'll get illuaminate to handle this.
 | 
			
		||||
(at
 | 
			
		||||
  (/src/main/resources/*/computercraft/lua/bios.lua
 | 
			
		||||
   /src/main/resources/*/computercraft/lua/rom/apis/)
 | 
			
		||||
  (linters -var:unused-global)
 | 
			
		||||
  (lint (allow-toplevel-global true)))
 | 
			
		||||
 | 
			
		||||
;; Silence some variable warnings in documentation stubs.
 | 
			
		||||
(at (/doc/stub/ /build/docs/luaJavadoc/)
 | 
			
		||||
  (linters -var:unused-global)
 | 
			
		||||
  (lint (allow-toplevel-global true)))
 | 
			
		||||
 | 
			
		||||
;; Suppress warnings for currently undocumented modules.
 | 
			
		||||
(at
 | 
			
		||||
  (; Lua APIs
 | 
			
		||||
   /src/main/resources/*/computercraft/lua/rom/apis/io.lua
 | 
			
		||||
   /src/main/resources/*/computercraft/lua/rom/apis/window.lua)
 | 
			
		||||
 | 
			
		||||
  (linters -doc:undocumented -doc:undocumented-arg -doc:undocumented-return))
 | 
			
		||||
 | 
			
		||||
;; Suppress warnings for various APIs using its own deprecated members.
 | 
			
		||||
(at
 | 
			
		||||
  (/src/main/resources/*/computercraft/lua/bios.lua
 | 
			
		||||
   /src/main/resources/*/computercraft/lua/rom/apis/turtle/turtle.lua)
 | 
			
		||||
  (linters -var:deprecated))
 | 
			
		||||
 | 
			
		||||
(at /src/test/resources/test-rom
 | 
			
		||||
  ; We should still be able to test deprecated members.
 | 
			
		||||
  (linters -var:deprecated)
 | 
			
		||||
 | 
			
		||||
  (lint
 | 
			
		||||
    (globals
 | 
			
		||||
      :max sleep write
 | 
			
		||||
      cct_test describe expect howlci fail it pending stub)))
 | 
			
		||||
 | 
			
		||||
(at /src/web/mount/expr_template.lua (lint (globals :max __expr__)))
 | 
			
		||||
							
								
								
									
										5
									
								
								jitpack.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								jitpack.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
before_install:
 | 
			
		||||
  - wget https://github.com/sormuras/bach/raw/master/install-jdk.sh
 | 
			
		||||
  - source ./install-jdk.sh --feature 16 --license GPL
 | 
			
		||||
jdk:
 | 
			
		||||
  - openjdk16
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								logo.png
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								logo.png
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 8.1 KiB  | 
@@ -1,6 +1,5 @@
 | 
			
		||||
pluginManagement {
 | 
			
		||||
    repositories {
 | 
			
		||||
        jcenter()
 | 
			
		||||
        maven {
 | 
			
		||||
            name = 'Fabric'
 | 
			
		||||
            url = 'https://maven.fabricmc.net/'
 | 
			
		||||
@@ -9,4 +8,4 @@ pluginManagement {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
rootProject.name = "cc-restiched"
 | 
			
		||||
rootProject.name = "cc-restitched"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,13 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.turtle.event.TurtleAction;
 | 
			
		||||
import dan200.computercraft.core.apis.http.options.Action;
 | 
			
		||||
import dan200.computercraft.core.apis.http.options.AddressRule;
 | 
			
		||||
import dan200.computercraft.shared.ComputerCraftRegistry.ModBlocks;
 | 
			
		||||
import dan200.computercraft.shared.common.ColourableRecipe;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.ClientComputerRegistry;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.ServerComputerRegistry;
 | 
			
		||||
@@ -30,20 +29,18 @@ import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
 | 
			
		||||
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
 | 
			
		||||
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
 | 
			
		||||
import net.fabricmc.loader.api.FabricLoader;
 | 
			
		||||
import net.minecraft.item.ItemGroup;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraft.util.Identifier;
 | 
			
		||||
import net.minecraft.util.registry.Registry;
 | 
			
		||||
import net.minecraft.core.Registry;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.world.item.CreativeModeTab;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import org.apache.logging.log4j.LogManager;
 | 
			
		||||
import org.apache.logging.log4j.Logger;
 | 
			
		||||
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.EnumSet;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.shared.ComputerCraftRegistry.ModBlocks;
 | 
			
		||||
import static dan200.computercraft.shared.ComputerCraftRegistry.init;
 | 
			
		||||
 | 
			
		||||
public final class ComputerCraft implements ModInitializer
 | 
			
		||||
@@ -72,6 +69,8 @@ public final class ComputerCraft implements ModInitializer
 | 
			
		||||
    ) );
 | 
			
		||||
    public static int httpMaxRequests = 16;
 | 
			
		||||
    public static int httpMaxWebsockets = 4;
 | 
			
		||||
    public static int httpDownloadBandwidth = 32 * 1024 * 1024;
 | 
			
		||||
    public static int httpUploadBandwidth = 32 * 1024 * 1024;
 | 
			
		||||
 | 
			
		||||
    public static boolean enableCommandBlock = false;
 | 
			
		||||
    public static int modemRange = 64;
 | 
			
		||||
@@ -81,6 +80,7 @@ public final class ComputerCraft implements ModInitializer
 | 
			
		||||
    public static int maxNotesPerTick = 8;
 | 
			
		||||
    public static MonitorRenderer monitorRenderer = MonitorRenderer.BEST;
 | 
			
		||||
    public static double monitorDistanceSq = 4096;
 | 
			
		||||
    public static int monitorDistance = 65;
 | 
			
		||||
    public static long monitorBandwidth = 1_000_000;
 | 
			
		||||
 | 
			
		||||
    public static boolean turtlesNeedFuel = true;
 | 
			
		||||
@@ -88,7 +88,6 @@ public final class ComputerCraft implements ModInitializer
 | 
			
		||||
    public static int advancedTurtleFuelLimit = 100000;
 | 
			
		||||
    public static boolean turtlesObeyBlockProtection = true;
 | 
			
		||||
    public static boolean turtlesCanPush = true;
 | 
			
		||||
    public static EnumSet<TurtleAction> turtleDisabledActions = EnumSet.noneOf( TurtleAction.class );
 | 
			
		||||
 | 
			
		||||
    public static int computerTermWidth = 51;
 | 
			
		||||
    public static int computerTermHeight = 19;
 | 
			
		||||
@@ -108,30 +107,30 @@ public final class ComputerCraft implements ModInitializer
 | 
			
		||||
    // Logging
 | 
			
		||||
    public static final Logger log = LogManager.getLogger( MOD_ID );
 | 
			
		||||
 | 
			
		||||
    public static ItemGroup MAIN_GROUP = FabricItemGroupBuilder.build( new Identifier( MOD_ID, "main" ), () -> new ItemStack( ModBlocks.COMPUTER_NORMAL ) );
 | 
			
		||||
    public static CreativeModeTab MAIN_GROUP = FabricItemGroupBuilder.build( new ResourceLocation( MOD_ID, "main" ), () -> new ItemStack( ModBlocks.COMPUTER_NORMAL ) );
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onInitialize()
 | 
			
		||||
    {
 | 
			
		||||
        ComputerCraftProxyCommon.init();
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "colour" ), ColourableRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "computer_upgrade" ), ComputerUpgradeRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "colour" ), ColourableRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "computer_upgrade" ), ComputerUpgradeRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER,
 | 
			
		||||
            new Identifier( ComputerCraft.MOD_ID, "pocket_computer_upgrade" ),
 | 
			
		||||
            new ResourceLocation( ComputerCraft.MOD_ID, "pocket_computer_upgrade" ),
 | 
			
		||||
            PocketComputerUpgradeRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "disk" ), DiskRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "printout" ), PrintoutRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "turtle" ), TurtleRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "turtle_upgrade" ), TurtleUpgradeRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "impostor_shaped" ), ImpostorRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "impostor_shapeless" ), ImpostorShapelessRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.LOOT_CONDITION_TYPE, new Identifier( ComputerCraft.MOD_ID, "block_named" ), BlockNamedEntityLootCondition.TYPE );
 | 
			
		||||
        Registry.register( Registry.LOOT_CONDITION_TYPE, new Identifier( ComputerCraft.MOD_ID, "player_creative" ), PlayerCreativeLootCondition.TYPE );
 | 
			
		||||
        Registry.register( Registry.LOOT_CONDITION_TYPE, new Identifier( ComputerCraft.MOD_ID, "has_id" ), HasComputerIdLootCondition.TYPE );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "disk" ), DiskRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "printout" ), PrintoutRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "turtle" ), TurtleRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "turtle_upgrade" ), TurtleUpgradeRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "impostor_shaped" ), ImpostorRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "impostor_shapeless" ), ImpostorShapelessRecipe.SERIALIZER );
 | 
			
		||||
        Registry.register( Registry.LOOT_CONDITION_TYPE, new ResourceLocation( ComputerCraft.MOD_ID, "block_named" ), BlockNamedEntityLootCondition.TYPE );
 | 
			
		||||
        Registry.register( Registry.LOOT_CONDITION_TYPE, new ResourceLocation( ComputerCraft.MOD_ID, "player_creative" ), PlayerCreativeLootCondition.TYPE );
 | 
			
		||||
        Registry.register( Registry.LOOT_CONDITION_TYPE, new ResourceLocation( ComputerCraft.MOD_ID, "has_id" ), HasComputerIdLootCondition.TYPE );
 | 
			
		||||
        init();
 | 
			
		||||
        FabricLoader.getInstance().getModContainer( MOD_ID ).ifPresent( modContainer -> {
 | 
			
		||||
            ResourceManagerHelper.registerBuiltinResourcePack( new Identifier( MOD_ID, "classic" ), modContainer, ResourcePackActivationType.NORMAL );
 | 
			
		||||
            ResourceManagerHelper.registerBuiltinResourcePack( new Identifier( MOD_ID, "overhaul" ), modContainer, ResourcePackActivationType.NORMAL );
 | 
			
		||||
            ResourceManagerHelper.registerBuiltinResourcePack( new ResourceLocation( MOD_ID, "classic" ), modContainer, ResourcePackActivationType.NORMAL );
 | 
			
		||||
            ResourceManagerHelper.registerBuiltinResourcePack( new ResourceLocation( MOD_ID, "overhaul" ), modContainer, ResourcePackActivationType.NORMAL );
 | 
			
		||||
        } );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI.IComputerCraftAPI;
 | 
			
		||||
@@ -32,14 +31,14 @@ import dan200.computercraft.shared.util.IDAssigner;
 | 
			
		||||
import dan200.computercraft.shared.wired.WiredNode;
 | 
			
		||||
import me.shedaniel.cloth.api.utils.v1.GameInstanceUtils;
 | 
			
		||||
import net.fabricmc.loader.api.FabricLoader;
 | 
			
		||||
import net.minecraft.block.entity.BlockEntity;
 | 
			
		||||
import net.minecraft.resource.ReloadableResourceManager;
 | 
			
		||||
import net.minecraft.core.BlockPos;
 | 
			
		||||
import net.minecraft.core.Direction;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.server.MinecraftServer;
 | 
			
		||||
import net.minecraft.util.Identifier;
 | 
			
		||||
import net.minecraft.util.math.BlockPos;
 | 
			
		||||
import net.minecraft.util.math.Direction;
 | 
			
		||||
import net.minecraft.world.BlockView;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
import net.minecraft.server.packs.resources.ReloadableResourceManager;
 | 
			
		||||
import net.minecraft.world.level.BlockGetter;
 | 
			
		||||
import net.minecraft.world.level.Level;
 | 
			
		||||
import net.minecraft.world.level.block.entity.BlockEntity;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
@@ -62,10 +61,10 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
 | 
			
		||||
        MinecraftServer server = GameInstanceUtils.getServer();
 | 
			
		||||
        if( server != null )
 | 
			
		||||
        {
 | 
			
		||||
            ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) server).getServerResourceManager().getResourceManager();
 | 
			
		||||
            ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) server).callGetResourceManager();
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                return manager.getResource( new Identifier( domain, subPath ) )
 | 
			
		||||
                return manager.getResource( new ResourceLocation( domain, subPath ) )
 | 
			
		||||
                    .getInputStream();
 | 
			
		||||
            }
 | 
			
		||||
            catch( IOException ignored )
 | 
			
		||||
@@ -80,11 +79,11 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getInstalledVersion()
 | 
			
		||||
    {
 | 
			
		||||
        if( this.version != null )
 | 
			
		||||
        if( version != null )
 | 
			
		||||
        {
 | 
			
		||||
            return this.version;
 | 
			
		||||
            return version;
 | 
			
		||||
        }
 | 
			
		||||
        return this.version = FabricLoader.getInstance()
 | 
			
		||||
        return version = FabricLoader.getInstance()
 | 
			
		||||
            .getModContainer( ComputerCraft.MOD_ID )
 | 
			
		||||
            .map( x -> x.getMetadata()
 | 
			
		||||
                .getVersion()
 | 
			
		||||
@@ -93,13 +92,13 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
 | 
			
		||||
    public int createUniqueNumberedSaveDir( @Nonnull Level world, @Nonnull String parentSubPath )
 | 
			
		||||
    {
 | 
			
		||||
        return IDAssigner.getNextId( parentSubPath );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
 | 
			
		||||
    public IWritableMount createSaveDirMount( @Nonnull Level world, @Nonnull String subPath, long capacity )
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
@@ -117,7 +116,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
 | 
			
		||||
        MinecraftServer server = GameInstanceUtils.getServer();
 | 
			
		||||
        if( server != null )
 | 
			
		||||
        {
 | 
			
		||||
            ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) server).getServerResourceManager().getResourceManager();
 | 
			
		||||
            ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) server).callGetResourceManager();
 | 
			
		||||
            ResourceMount mount = ResourceMount.get( domain, subPath, manager );
 | 
			
		||||
            return mount.exists( "" ) ? mount : null;
 | 
			
		||||
        }
 | 
			
		||||
@@ -143,7 +142,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
 | 
			
		||||
    public int getBundledRedstoneOutput( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side )
 | 
			
		||||
    {
 | 
			
		||||
        return BundledRedstone.getDefaultOutput( world, pos, side );
 | 
			
		||||
    }
 | 
			
		||||
@@ -188,7 +187,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    @Override
 | 
			
		||||
    public IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
 | 
			
		||||
    public IWiredElement getWiredElementAt( @Nonnull BlockGetter world, @Nonnull BlockPos pos, @Nonnull Direction side )
 | 
			
		||||
    {
 | 
			
		||||
        BlockEntity tile = world.getBlockEntity( pos );
 | 
			
		||||
        if( tile instanceof TileCable )
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.filesystem.IMount;
 | 
			
		||||
@@ -21,10 +20,10 @@ import dan200.computercraft.api.peripheral.IPeripheralProvider;
 | 
			
		||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
 | 
			
		||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
 | 
			
		||||
import net.minecraft.util.math.BlockPos;
 | 
			
		||||
import net.minecraft.util.math.Direction;
 | 
			
		||||
import net.minecraft.world.BlockView;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
import net.minecraft.core.BlockPos;
 | 
			
		||||
import net.minecraft.core.Direction;
 | 
			
		||||
import net.minecraft.world.level.BlockGetter;
 | 
			
		||||
import net.minecraft.world.level.Level;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
@@ -32,19 +31,11 @@ import javax.annotation.Nullable;
 | 
			
		||||
/**
 | 
			
		||||
 * The static entry point to the ComputerCraft API.
 | 
			
		||||
 *
 | 
			
		||||
 * Members in this class must be called after mod_ComputerCraft has been initialised, but may be called before it is fully loaded.
 | 
			
		||||
 * Members in this class must be called after mod_ComputerCraft has been initialised, but may be called before it is
 | 
			
		||||
 * fully loaded.
 | 
			
		||||
 */
 | 
			
		||||
public final class ComputerCraftAPI
 | 
			
		||||
{
 | 
			
		||||
    private static IComputerCraftAPI instance;
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static String getAPIVersion()
 | 
			
		||||
    {
 | 
			
		||||
        return getInstalledVersion();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static String getInstalledVersion()
 | 
			
		||||
    {
 | 
			
		||||
@@ -52,23 +43,10 @@ public final class ComputerCraftAPI
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    private static IComputerCraftAPI getInstance()
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static String getAPIVersion()
 | 
			
		||||
    {
 | 
			
		||||
        if( instance != null )
 | 
			
		||||
        {
 | 
			
		||||
            return instance;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            return instance = (IComputerCraftAPI) Class.forName( "dan200.computercraft.ComputerCraftAPIImpl" )
 | 
			
		||||
                .getField( "INSTANCE" )
 | 
			
		||||
                .get( null );
 | 
			
		||||
        }
 | 
			
		||||
        catch( ReflectiveOperationException e )
 | 
			
		||||
        {
 | 
			
		||||
            throw new IllegalStateException( "Cannot find ComputerCraft API", e );
 | 
			
		||||
        }
 | 
			
		||||
        return getInstalledVersion();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -80,10 +58,11 @@ public final class ComputerCraftAPI
 | 
			
		||||
     * @param parentSubPath The folder path within the save directory where the new directory should be created. eg: "computercraft/disk"
 | 
			
		||||
     * @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.
 | 
			
		||||
     *
 | 
			
		||||
     * eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now available for writing.
 | 
			
		||||
     * @see #createSaveDirMount(World, String, long)
 | 
			
		||||
     * eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now
 | 
			
		||||
     * available for writing.
 | 
			
		||||
     * @see #createSaveDirMount(Level, String, long)
 | 
			
		||||
     */
 | 
			
		||||
    public static int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
 | 
			
		||||
    public static int createUniqueNumberedSaveDir( @Nonnull Level world, @Nonnull String parentSubPath )
 | 
			
		||||
    {
 | 
			
		||||
        return getInstance().createUniqueNumberedSaveDir( world, parentSubPath );
 | 
			
		||||
    }
 | 
			
		||||
@@ -91,23 +70,23 @@ public final class ComputerCraftAPI
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a file system mount that maps to a subfolder of the save directory for a given world, and returns it.
 | 
			
		||||
     *
 | 
			
		||||
     * Use in conjunction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the users save directory onto a computers
 | 
			
		||||
     * file system.
 | 
			
		||||
     * Use in conjunction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the
 | 
			
		||||
     * users save directory onto a computers file system.
 | 
			
		||||
     *
 | 
			
		||||
     * @param world    The world for which the save dir can be found. This should be the server side world object.
 | 
			
		||||
     * @param subPath  The folder path within the save directory that the mount should map to. eg: "computer/disk/42". Use createUniqueNumberedSaveDir()
 | 
			
		||||
     *                 to create a new numbered folder to use.
 | 
			
		||||
     * @param subPath  The folder path within the save directory that the mount should map to. eg: "computer/disk/42".
 | 
			
		||||
     *                 Use createUniqueNumberedSaveDir() to create a new numbered folder to use.
 | 
			
		||||
     * @param capacity The amount of data that can be stored in the directory before it fills up, in bytes.
 | 
			
		||||
     * @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable() to mount this on a
 | 
			
		||||
     * Computers' file system.
 | 
			
		||||
     * @see #createUniqueNumberedSaveDir(World, String)
 | 
			
		||||
     * @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable()
 | 
			
		||||
     * to mount this on a Computers' file system.
 | 
			
		||||
     * @see #createUniqueNumberedSaveDir(Level, String)
 | 
			
		||||
     * @see IComputerAccess#mount(String, IMount)
 | 
			
		||||
     * @see IComputerAccess#mountWritable(String, IWritableMount)
 | 
			
		||||
     * @see IMount
 | 
			
		||||
     * @see IWritableMount
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public static IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
 | 
			
		||||
    public static IWritableMount createSaveDirMount( @Nonnull Level world, @Nonnull String subPath, long capacity )
 | 
			
		||||
    {
 | 
			
		||||
        return getInstance().createSaveDirMount( world, subPath, capacity );
 | 
			
		||||
    }
 | 
			
		||||
@@ -115,8 +94,8 @@ public final class ComputerCraftAPI
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a file system mount to a resource folder, and returns it.
 | 
			
		||||
     *
 | 
			
		||||
     * Use in conjunction with {@link IComputerAccess#mount} or {@link IComputerAccess#mountWritable} to mount a resource folder onto a computer's file
 | 
			
		||||
     * system.
 | 
			
		||||
     * Use in conjunction with {@link IComputerAccess#mount} or {@link IComputerAccess#mountWritable} to mount a
 | 
			
		||||
     * resource folder onto a computer's file system.
 | 
			
		||||
     *
 | 
			
		||||
     * The files in this mount will be a combination of files in all mod jar, and data packs that contain
 | 
			
		||||
     * resources with the same domain and path. For instance, ComputerCraft's resources are stored in
 | 
			
		||||
@@ -137,7 +116,7 @@ public final class ComputerCraftAPI
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Registers a peripheral provider to convert blocks into {@link IPeripheral} implementations.
 | 
			
		||||
     * rers a peripheral provider to convert blocks into {@link IPeripheral} implementations.
 | 
			
		||||
     *
 | 
			
		||||
     * @param provider The peripheral provider to register.
 | 
			
		||||
     * @see IPeripheral
 | 
			
		||||
@@ -160,8 +139,9 @@ public final class ComputerCraftAPI
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Registers a new turtle turtle for use in ComputerCraft. After calling this, users should be able to craft Turtles with your new turtle. It is
 | 
			
		||||
     * recommended to call this during the load() method of your mod.
 | 
			
		||||
     * Registers a new turtle turtle for use in ComputerCraft. After calling this,
 | 
			
		||||
     * users should be able to craft Turtles with your new turtle. It is recommended to call
 | 
			
		||||
     * this during the load() method of your mod.
 | 
			
		||||
     *
 | 
			
		||||
     * @param upgrade The turtle upgrade to register.
 | 
			
		||||
     * @see ITurtleUpgrade
 | 
			
		||||
@@ -188,11 +168,11 @@ public final class ComputerCraftAPI
 | 
			
		||||
     * @param world The world this block is in.
 | 
			
		||||
     * @param pos   The position this block is at.
 | 
			
		||||
     * @param side  The side to extract the bundled redstone output from.
 | 
			
		||||
     * @return If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned. If there is no block
 | 
			
		||||
     * capable of emitting bundled redstone at the location, -1 will be returned.
 | 
			
		||||
     * @return If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned.
 | 
			
		||||
     * If there is no block capable of emitting bundled redstone at the location, -1 will be returned.
 | 
			
		||||
     * @see IBundledRedstoneProvider
 | 
			
		||||
     */
 | 
			
		||||
    public static int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
 | 
			
		||||
    public static int getBundledRedstoneOutput( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side )
 | 
			
		||||
    {
 | 
			
		||||
        return getInstance().getBundledRedstoneOutput( world, pos, side );
 | 
			
		||||
    }
 | 
			
		||||
@@ -251,20 +231,38 @@ public final class ComputerCraftAPI
 | 
			
		||||
     * @see IWiredElement#getNode()
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public static IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
 | 
			
		||||
    public static IWiredElement getWiredElementAt( @Nonnull BlockGetter world, @Nonnull BlockPos pos, @Nonnull Direction side )
 | 
			
		||||
    {
 | 
			
		||||
        return getInstance().getWiredElementAt( world, pos, side );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static IComputerCraftAPI instance;
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    private static IComputerCraftAPI getInstance()
 | 
			
		||||
    {
 | 
			
		||||
        if( instance != null ) return instance;
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            return instance = (IComputerCraftAPI) Class.forName( "dan200.computercraft.ComputerCraftAPIImpl" )
 | 
			
		||||
                .getField( "INSTANCE" ).get( null );
 | 
			
		||||
        }
 | 
			
		||||
        catch( ReflectiveOperationException e )
 | 
			
		||||
        {
 | 
			
		||||
            throw new IllegalStateException( "Cannot find ComputerCraft API", e );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public interface IComputerCraftAPI
 | 
			
		||||
    {
 | 
			
		||||
        @Nonnull
 | 
			
		||||
        String getInstalledVersion();
 | 
			
		||||
 | 
			
		||||
        int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath );
 | 
			
		||||
        int createUniqueNumberedSaveDir( @Nonnull Level world, @Nonnull String parentSubPath );
 | 
			
		||||
 | 
			
		||||
        @Nullable
 | 
			
		||||
        IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity );
 | 
			
		||||
        IWritableMount createSaveDirMount( @Nonnull Level world, @Nonnull String subPath, long capacity );
 | 
			
		||||
 | 
			
		||||
        @Nullable
 | 
			
		||||
        IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath );
 | 
			
		||||
@@ -277,7 +275,7 @@ public final class ComputerCraftAPI
 | 
			
		||||
 | 
			
		||||
        void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider );
 | 
			
		||||
 | 
			
		||||
        int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
 | 
			
		||||
        int getBundledRedstoneOutput( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side );
 | 
			
		||||
 | 
			
		||||
        void registerMediaProvider( @Nonnull IMediaProvider provider );
 | 
			
		||||
 | 
			
		||||
@@ -292,6 +290,6 @@ public final class ComputerCraftAPI
 | 
			
		||||
        IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element );
 | 
			
		||||
 | 
			
		||||
        @Nullable
 | 
			
		||||
        IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side );
 | 
			
		||||
        IWiredElement getWiredElementAt( @Nonnull BlockGetter world, @Nonnull BlockPos pos, @Nonnull Direction side );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,15 +1,15 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
package dan200.computercraft.api;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraft.nbt.CompoundTag;
 | 
			
		||||
import net.minecraft.util.Identifier;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
@@ -28,7 +28,7 @@ public interface IUpgradeBase
 | 
			
		||||
     * @return The unique ID for this upgrade.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    Identifier getUpgradeID();
 | 
			
		||||
    ResourceLocation getUpgradeID();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Return an unlocalised string to describe this type of computer in item names.
 | 
			
		||||
@@ -67,8 +67,6 @@ public interface IUpgradeBase
 | 
			
		||||
     * @param stack The stack to check. This is guaranteed to be non-empty and have the same item as
 | 
			
		||||
     *              {@link #getCraftingItem()}.
 | 
			
		||||
     * @return If this stack may be used to equip this upgrade.
 | 
			
		||||
     * @see net.minecraftforge.common.crafting.NBTIngredient#test(ItemStack) For the implementation of the default
 | 
			
		||||
     * check.
 | 
			
		||||
     */
 | 
			
		||||
    default boolean isItemSuitable( @Nonnull ItemStack stack )
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,21 +1,20 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.client;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.fabric.mixin.AffineTransformationAccess;
 | 
			
		||||
import com.mojang.blaze3d.vertex.PoseStack;
 | 
			
		||||
import com.mojang.math.Transformation;
 | 
			
		||||
import com.mojang.math.Vector3f;
 | 
			
		||||
import net.fabricmc.api.EnvType;
 | 
			
		||||
import net.fabricmc.api.Environment;
 | 
			
		||||
import net.minecraft.client.MinecraftClient;
 | 
			
		||||
import net.minecraft.client.render.model.BakedModel;
 | 
			
		||||
import net.minecraft.client.render.model.BakedModelManager;
 | 
			
		||||
import net.minecraft.client.util.ModelIdentifier;
 | 
			
		||||
import net.minecraft.client.util.math.AffineTransformation;
 | 
			
		||||
import net.minecraft.client.util.math.MatrixStack;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraft.client.Minecraft;
 | 
			
		||||
import net.minecraft.client.resources.model.BakedModel;
 | 
			
		||||
import net.minecraft.client.resources.model.ModelManager;
 | 
			
		||||
import net.minecraft.client.resources.model.ModelResourceLocation;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
@@ -27,9 +26,9 @@ import java.util.Objects;
 | 
			
		||||
public final class TransformedModel
 | 
			
		||||
{
 | 
			
		||||
    private final BakedModel model;
 | 
			
		||||
    private final AffineTransformation matrix;
 | 
			
		||||
    private final Transformation matrix;
 | 
			
		||||
 | 
			
		||||
    public TransformedModel( @Nonnull BakedModel model, @Nonnull AffineTransformation matrix )
 | 
			
		||||
    public TransformedModel( @Nonnull BakedModel model, @Nonnull Transformation matrix )
 | 
			
		||||
    {
 | 
			
		||||
        this.model = Objects.requireNonNull( model );
 | 
			
		||||
        this.matrix = Objects.requireNonNull( matrix );
 | 
			
		||||
@@ -38,57 +37,45 @@ public final class TransformedModel
 | 
			
		||||
    public TransformedModel( @Nonnull BakedModel model )
 | 
			
		||||
    {
 | 
			
		||||
        this.model = Objects.requireNonNull( model );
 | 
			
		||||
        this.matrix = AffineTransformation.identity();
 | 
			
		||||
        matrix = Transformation.identity();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static TransformedModel of( @Nonnull ModelIdentifier location )
 | 
			
		||||
    public static TransformedModel of( @Nonnull ModelResourceLocation location )
 | 
			
		||||
    {
 | 
			
		||||
        BakedModelManager modelManager = MinecraftClient.getInstance()
 | 
			
		||||
            .getBakedModelManager();
 | 
			
		||||
        ModelManager modelManager = Minecraft.getInstance().getModelManager();
 | 
			
		||||
        return new TransformedModel( modelManager.getModel( location ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static TransformedModel of( @Nonnull ItemStack item, @Nonnull AffineTransformation transform )
 | 
			
		||||
    public static TransformedModel of( @Nonnull ItemStack item, @Nonnull Transformation transform )
 | 
			
		||||
    {
 | 
			
		||||
        BakedModel model = MinecraftClient.getInstance()
 | 
			
		||||
            .getItemRenderer()
 | 
			
		||||
            .getModels()
 | 
			
		||||
            .getModel( item );
 | 
			
		||||
        BakedModel model = Minecraft.getInstance().getItemRenderer().getItemModelShaper().getItemModel( item );
 | 
			
		||||
        return new TransformedModel( model, transform );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public BakedModel getModel()
 | 
			
		||||
    {
 | 
			
		||||
        return this.model;
 | 
			
		||||
        return model;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public AffineTransformation getMatrix()
 | 
			
		||||
    public Transformation getMatrix()
 | 
			
		||||
    {
 | 
			
		||||
        return this.matrix;
 | 
			
		||||
        return matrix;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void push( MatrixStack matrixStack )
 | 
			
		||||
    public void push( PoseStack matrixStack )
 | 
			
		||||
    {
 | 
			
		||||
        matrixStack.push();
 | 
			
		||||
        matrixStack.pushPose();
 | 
			
		||||
 | 
			
		||||
        AffineTransformationAccess access = (AffineTransformationAccess) (Object) this.matrix;
 | 
			
		||||
        if( access.getTranslation() != null )
 | 
			
		||||
        {
 | 
			
		||||
            matrixStack.translate( access.getTranslation().getX(), access.getTranslation().getY(), access.getTranslation().getZ() );
 | 
			
		||||
        }
 | 
			
		||||
        Vector3f translation = matrix.getTranslation();
 | 
			
		||||
        matrixStack.translate( translation.x(), translation.y(), translation.z() );
 | 
			
		||||
 | 
			
		||||
        matrixStack.multiply( this.matrix.getRotation2() );
 | 
			
		||||
        matrixStack.mulPose( matrix.getLeftRotation() );
 | 
			
		||||
 | 
			
		||||
        if( access.getScale() != null )
 | 
			
		||||
        {
 | 
			
		||||
            matrixStack.scale( access.getScale().getX(), access.getScale().getY(), access.getScale().getZ() );
 | 
			
		||||
        }
 | 
			
		||||
        Vector3f scale = matrix.getScale();
 | 
			
		||||
        matrixStack.scale( scale.x(), scale.y(), scale.z() );
 | 
			
		||||
 | 
			
		||||
        if( access.getRotation1() != null )
 | 
			
		||||
        {
 | 
			
		||||
            matrixStack.multiply( access.getRotation1() );
 | 
			
		||||
        }
 | 
			
		||||
        matrixStack.mulPose( matrix.getRightRotation() );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.filesystem;
 | 
			
		||||
 | 
			
		||||
import java.nio.file.attribute.BasicFileAttributes;
 | 
			
		||||
@@ -47,13 +46,13 @@ final class FileAttributes implements BasicFileAttributes
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isRegularFile()
 | 
			
		||||
    {
 | 
			
		||||
        return !this.isDirectory;
 | 
			
		||||
        return !isDirectory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isDirectory()
 | 
			
		||||
    {
 | 
			
		||||
        return this.isDirectory;
 | 
			
		||||
        return isDirectory;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -71,7 +70,7 @@ final class FileAttributes implements BasicFileAttributes
 | 
			
		||||
    @Override
 | 
			
		||||
    public long size()
 | 
			
		||||
    {
 | 
			
		||||
        return this.size;
 | 
			
		||||
        return size;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.filesystem;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
@@ -31,12 +30,12 @@ public class FileOperationException extends IOException
 | 
			
		||||
    public FileOperationException( @Nonnull String message )
 | 
			
		||||
    {
 | 
			
		||||
        super( Objects.requireNonNull( message, "message cannot be null" ) );
 | 
			
		||||
        this.filename = null;
 | 
			
		||||
        filename = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public String getFilename()
 | 
			
		||||
    {
 | 
			
		||||
        return this.filename;
 | 
			
		||||
        return filename;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.filesystem;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,13 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.filesystem;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IComputerAccess;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
import net.minecraft.world.level.Level;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
@@ -17,55 +16,20 @@ import java.nio.file.attribute.BasicFileAttributes;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a read only part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)}.
 | 
			
		||||
 * Represents a read only part of a virtual filesystem that can be mounted onto a computer using
 | 
			
		||||
 * {@link IComputerAccess#mount(String, IMount)}.
 | 
			
		||||
 *
 | 
			
		||||
 * Ready made implementations of this interface can be created using {@link ComputerCraftAPI#createSaveDirMount(World, String, long)} or {@link
 | 
			
		||||
 * ComputerCraftAPI#createResourceMount(String, String)}, or you're free to implement it yourselves!
 | 
			
		||||
 * Ready made implementations of this interface can be created using
 | 
			
		||||
 * {@link ComputerCraftAPI#createSaveDirMount(Level, String, long)} or
 | 
			
		||||
 * {@link ComputerCraftAPI#createResourceMount(String, String)}, or you're free to implement it yourselves!
 | 
			
		||||
 *
 | 
			
		||||
 * @see ComputerCraftAPI#createSaveDirMount(World, String, long)
 | 
			
		||||
 * @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
 | 
			
		||||
 * @see ComputerCraftAPI#createResourceMount(String, String)
 | 
			
		||||
 * @see IComputerAccess#mount(String, IMount)
 | 
			
		||||
 * @see IWritableMount
 | 
			
		||||
 */
 | 
			
		||||
public interface IMount
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the file names of all the files in a directory.
 | 
			
		||||
     *
 | 
			
		||||
     * @param path     A file path in normalised format, relative to the mount location. ie: "programs/myprograms".
 | 
			
		||||
     * @param contents A list of strings. Add all the file names to this list.
 | 
			
		||||
     * @throws IOException If the file was not a directory, or could not be listed.
 | 
			
		||||
     */
 | 
			
		||||
    void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Opens a file with a given path, and returns an {@link ReadableByteChannel} representing its contents.
 | 
			
		||||
     *
 | 
			
		||||
     * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
 | 
			
		||||
     * @return A channel representing the contents of the file. If the channel implements {@link java.nio.channels.SeekableByteChannel}, one will be able to
 | 
			
		||||
     * seek to arbitrary positions when using binary mode.
 | 
			
		||||
     * @throws IOException If the file does not exist, or could not be opened.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    ReadableByteChannel openForRead( @Nonnull String path ) throws IOException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get attributes about the given file.
 | 
			
		||||
     *
 | 
			
		||||
     * @param path The path to query.
 | 
			
		||||
     * @return File attributes for the given file.
 | 
			
		||||
     * @throws IOException If the file does not exist, or attributes could not be fetched.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    default BasicFileAttributes getAttributes( @Nonnull String path ) throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        if( !this.exists( path ) )
 | 
			
		||||
        {
 | 
			
		||||
            throw new FileOperationException( path, "No such file" );
 | 
			
		||||
        }
 | 
			
		||||
        return new FileAttributes( this.isDirectory( path ), this.getSize( path ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns whether a file with a given path exists or not.
 | 
			
		||||
     *
 | 
			
		||||
@@ -84,6 +48,15 @@ public interface IMount
 | 
			
		||||
     */
 | 
			
		||||
    boolean isDirectory( @Nonnull String path ) throws IOException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the file names of all the files in a directory.
 | 
			
		||||
     *
 | 
			
		||||
     * @param path     A file path in normalised format, relative to the mount location. ie: "programs/myprograms".
 | 
			
		||||
     * @param contents A list of strings. Add all the file names to this list.
 | 
			
		||||
     * @throws IOException If the file was not a directory, or could not be listed.
 | 
			
		||||
     */
 | 
			
		||||
    void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the size of a file with a given path, in bytes.
 | 
			
		||||
     *
 | 
			
		||||
@@ -92,4 +65,30 @@ public interface IMount
 | 
			
		||||
     * @throws IOException If the file does not exist, or its size could not be determined.
 | 
			
		||||
     */
 | 
			
		||||
    long getSize( @Nonnull String path ) throws IOException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Opens a file with a given path, and returns an {@link ReadableByteChannel} representing its contents.
 | 
			
		||||
     *
 | 
			
		||||
     * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
 | 
			
		||||
     * @return A channel representing the contents of the file. If the channel implements
 | 
			
		||||
     * {@link java.nio.channels.SeekableByteChannel}, one will be able to seek to arbitrary positions when using binary
 | 
			
		||||
     * mode.
 | 
			
		||||
     * @throws IOException If the file does not exist, or could not be opened.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    ReadableByteChannel openForRead( @Nonnull String path ) throws IOException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get attributes about the given file.
 | 
			
		||||
     *
 | 
			
		||||
     * @param path The path to query.
 | 
			
		||||
     * @return File attributes for the given file.
 | 
			
		||||
     * @throws IOException If the file does not exist, or attributes could not be fetched.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    default BasicFileAttributes getAttributes( @Nonnull String path ) throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        if( !exists( path ) ) throw new FileOperationException( path, "No such file" );
 | 
			
		||||
        return new FileAttributes( isDirectory( path ), getSize( path ) );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,13 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.filesystem;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IComputerAccess;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
import net.minecraft.world.level.Level;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
@@ -17,13 +16,13 @@ import java.nio.channels.WritableByteChannel;
 | 
			
		||||
import java.util.OptionalLong;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)} or {@link
 | 
			
		||||
 * IComputerAccess#mountWritable(String, IWritableMount)}, that can also be written to.
 | 
			
		||||
 * Represents a part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)}
 | 
			
		||||
 * or {@link IComputerAccess#mountWritable(String, IWritableMount)}, that can also be written to.
 | 
			
		||||
 *
 | 
			
		||||
 * Ready made implementations of this interface can be created using {@link ComputerCraftAPI#createSaveDirMount(World, String, long)}, or you're free to
 | 
			
		||||
 * implement it yourselves!
 | 
			
		||||
 * Ready made implementations of this interface can be created using
 | 
			
		||||
 * {@link ComputerCraftAPI#createSaveDirMount(Level, String, long)}, or you're free to implement it yourselves!
 | 
			
		||||
 *
 | 
			
		||||
 * @see ComputerCraftAPI#createSaveDirMount(World, String, long)
 | 
			
		||||
 * @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
 | 
			
		||||
 * @see IComputerAccess#mount(String, IMount)
 | 
			
		||||
 * @see IComputerAccess#mountWritable(String, IWritableMount)
 | 
			
		||||
 * @see IMount
 | 
			
		||||
@@ -50,8 +49,8 @@ public interface IWritableMount extends IMount
 | 
			
		||||
     * Opens a file with a given path, and returns an {@link OutputStream} for writing to it.
 | 
			
		||||
     *
 | 
			
		||||
     * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
 | 
			
		||||
     * @return A stream for writing to. If the channel implements {@link java.nio.channels.SeekableByteChannel}, one will be able to seek to arbitrary
 | 
			
		||||
     * positions when using binary mode.
 | 
			
		||||
     * @return A stream for writing to. If the channel implements {@link java.nio.channels.SeekableByteChannel}, one
 | 
			
		||||
     * will be able to seek to arbitrary positions when using binary mode.
 | 
			
		||||
     * @throws IOException If the file could not be opened for writing.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
@@ -61,16 +60,16 @@ public interface IWritableMount extends IMount
 | 
			
		||||
     * Opens a file with a given path, and returns an {@link OutputStream} for appending to it.
 | 
			
		||||
     *
 | 
			
		||||
     * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
 | 
			
		||||
     * @return A stream for writing to. If the channel implements {@link java.nio.channels.SeekableByteChannel}, one will be able to seek to arbitrary
 | 
			
		||||
     * positions when using binary mode.
 | 
			
		||||
     * @return A stream for writing to. If the channel implements {@link java.nio.channels.SeekableByteChannel}, one
 | 
			
		||||
     * will be able to seek to arbitrary positions when using binary mode.
 | 
			
		||||
     * @throws IOException If the file could not be opened for writing.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    WritableByteChannel openForAppend( @Nonnull String path ) throws IOException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the amount of free space on the mount, in bytes. You should decrease this value as the user writes to the mount, and write operations should fail
 | 
			
		||||
     * once it reaches zero.
 | 
			
		||||
     * Get the amount of free space on the mount, in bytes. You should decrease this value as the user writes to the
 | 
			
		||||
     * mount, and write operations should fail once it reaches zero.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The amount of free space, in bytes.
 | 
			
		||||
     * @throws IOException If the remaining space could not be computed.
 | 
			
		||||
@@ -78,7 +77,8 @@ public interface IWritableMount extends IMount
 | 
			
		||||
    long getRemainingSpace() throws IOException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the capacity of this mount. This should be equal to the size of all files/directories on this mount, minus the {@link #getRemainingSpace()}.
 | 
			
		||||
     * Get the capacity of this mount. This should be equal to the size of all files/directories on this mount, minus
 | 
			
		||||
     * the {@link #getRemainingSpace()}.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The capacity of this mount, in bytes.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
@@ -9,7 +9,8 @@ import dan200.computercraft.api.ComputerCraftAPI;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheral;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheralProvider;
 | 
			
		||||
import dan200.computercraft.core.asm.LuaMethod;
 | 
			
		||||
import net.minecraft.util.Identifier;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.world.Container;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
@@ -18,20 +19,19 @@ import javax.annotation.Nonnull;
 | 
			
		||||
 *
 | 
			
		||||
 * Unlike normal objects ({@link IDynamicLuaObject} or {@link IPeripheral}), methods do not target this object but
 | 
			
		||||
 * instead are defined as {@code static} and accept their target as the first parameter. This allows you to inject
 | 
			
		||||
 * methods onto objects you do not own, as well as declaring methods for a specific "trait" (for instance, a
 | 
			
		||||
 * {@link Capability}).
 | 
			
		||||
 * methods onto objects you do not own, as well as declaring methods for a specific "trait" (well, interface).
 | 
			
		||||
 *
 | 
			
		||||
 * Currently the "generic peripheral" system is incompatible with normal peripherals. Normal {@link IPeripheralProvider}
 | 
			
		||||
 * or {@link IPeripheral} implementations take priority. Tile entities which use this system are given a peripheral name
 | 
			
		||||
 * determined by their id, rather than any peripheral provider. This will hopefully change in the future, once a suitable
 | 
			
		||||
 * design has been established.
 | 
			
		||||
 *
 | 
			
		||||
 * For example, the main CC: Tweaked mod defines a generic source for inventories, which works on {@link IItemHandler}s:
 | 
			
		||||
 * For example, the main CC: Tweaked mod defines a generic source for inventories, which works on {@link Container}s:
 | 
			
		||||
 *
 | 
			
		||||
 * <pre>{@code
 | 
			
		||||
 * public class InventoryMethods implements GenericSource {
 | 
			
		||||
 *     \@LuaFunction( mainThread = true )
 | 
			
		||||
 *     public static int size(IItemHandler inventory) {
 | 
			
		||||
 *     public static int size(Container inventory) {
 | 
			
		||||
 *         return inventory.getSlots();
 | 
			
		||||
 *     }
 | 
			
		||||
 *
 | 
			
		||||
@@ -40,8 +40,6 @@ import javax.annotation.Nonnull;
 | 
			
		||||
 * }</pre>
 | 
			
		||||
 *
 | 
			
		||||
 * @see ComputerCraftAPI#registerGenericSource(GenericSource)
 | 
			
		||||
 * @see ComputerCraftAPI#registerGenericCapability(Capability) New capabilities (those not built into Forge) must be
 | 
			
		||||
 * explicitly given to the generic peripheral system, as there is no way to enumerate all capabilities.
 | 
			
		||||
 */
 | 
			
		||||
public interface GenericSource
 | 
			
		||||
{
 | 
			
		||||
@@ -54,5 +52,5 @@ public interface GenericSource
 | 
			
		||||
     * @return This source's identifier.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    Identifier id();
 | 
			
		||||
    ResourceLocation id();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
@@ -19,25 +18,6 @@ import static dan200.computercraft.api.lua.LuaValues.checkFinite;
 | 
			
		||||
 */
 | 
			
		||||
public interface IArguments
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Drop a number of arguments. The returned arguments instance will access arguments at position {@code i + count}, rather than {@code i}. However,
 | 
			
		||||
     * errors will still use the given argument index.
 | 
			
		||||
     *
 | 
			
		||||
     * @param count The number of arguments to drop.
 | 
			
		||||
     * @return The new {@link IArguments} instance.
 | 
			
		||||
     */
 | 
			
		||||
    IArguments drop( int count );
 | 
			
		||||
 | 
			
		||||
    default Object[] getAll()
 | 
			
		||||
    {
 | 
			
		||||
        Object[] result = new Object[this.count()];
 | 
			
		||||
        for( int i = 0; i < result.length; i++ )
 | 
			
		||||
        {
 | 
			
		||||
            result[i] = this.get( i );
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the number of arguments passed to this function.
 | 
			
		||||
     *
 | 
			
		||||
@@ -63,45 +43,19 @@ public interface IArguments
 | 
			
		||||
    Object get( int index );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as an integer.
 | 
			
		||||
     * Drop a number of arguments. The returned arguments instance will access arguments at position {@code i + count},
 | 
			
		||||
     * rather than {@code i}. However, errors will still use the given argument index.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not an integer.
 | 
			
		||||
     * @param count The number of arguments to drop.
 | 
			
		||||
     * @return The new {@link IArguments} instance.
 | 
			
		||||
     */
 | 
			
		||||
    default int getInt( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return (int) this.getLong( index );
 | 
			
		||||
    }
 | 
			
		||||
    IArguments drop( int count );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a long.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not a long.
 | 
			
		||||
     */
 | 
			
		||||
    default long getLong( int index ) throws LuaException
 | 
			
		||||
    default Object[] getAll()
 | 
			
		||||
    {
 | 
			
		||||
        Object value = this.get( index );
 | 
			
		||||
        if( !(value instanceof Number) )
 | 
			
		||||
        {
 | 
			
		||||
            throw LuaValues.badArgumentOf( index, "number", value );
 | 
			
		||||
        }
 | 
			
		||||
        return LuaValues.checkFiniteNum( index, (Number) value )
 | 
			
		||||
            .longValue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a finite number (not infinite or NaN).
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not finite.
 | 
			
		||||
     */
 | 
			
		||||
    default double getFiniteDouble( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return checkFinite( index, this.getDouble( index ) );
 | 
			
		||||
        Object[] result = new Object[count()];
 | 
			
		||||
        for( int i = 0; i < result.length; i++ ) result[i] = get( i );
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -114,14 +68,49 @@ public interface IArguments
 | 
			
		||||
     */
 | 
			
		||||
    default double getDouble( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = this.get( index );
 | 
			
		||||
        if( !(value instanceof Number) )
 | 
			
		||||
        {
 | 
			
		||||
            throw LuaValues.badArgumentOf( index, "number", value );
 | 
			
		||||
        }
 | 
			
		||||
        Object value = get( index );
 | 
			
		||||
        if( !(value instanceof Number) ) throw LuaValues.badArgumentOf( index, "number", value );
 | 
			
		||||
        return ((Number) value).doubleValue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as an integer.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not an integer.
 | 
			
		||||
     */
 | 
			
		||||
    default int getInt( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return (int) getLong( index );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a long.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not a long.
 | 
			
		||||
     */
 | 
			
		||||
    default long getLong( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = get( index );
 | 
			
		||||
        if( !(value instanceof Number) ) throw LuaValues.badArgumentOf( index, "number", value );
 | 
			
		||||
        return LuaValues.checkFiniteNum( index, (Number) value ).longValue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a finite number (not infinite or NaN).
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not finite.
 | 
			
		||||
     */
 | 
			
		||||
    default double getFiniteDouble( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return checkFinite( index, getDouble( index ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a boolean.
 | 
			
		||||
     *
 | 
			
		||||
@@ -131,27 +120,11 @@ public interface IArguments
 | 
			
		||||
     */
 | 
			
		||||
    default boolean getBoolean( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = this.get( index );
 | 
			
		||||
        if( !(value instanceof Boolean) )
 | 
			
		||||
        {
 | 
			
		||||
            throw LuaValues.badArgumentOf( index, "boolean", value );
 | 
			
		||||
        }
 | 
			
		||||
        Object value = get( index );
 | 
			
		||||
        if( !(value instanceof Boolean) ) throw LuaValues.badArgumentOf( index, "boolean", value );
 | 
			
		||||
        return (Boolean) value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a string argument as a byte array.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value. This is a <em>read only</em> buffer.
 | 
			
		||||
     * @throws LuaException If the value is not a string.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    default ByteBuffer getBytes( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return LuaValues.encode( this.getString( index ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a string.
 | 
			
		||||
     *
 | 
			
		||||
@@ -162,14 +135,24 @@ public interface IArguments
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    default String getString( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = this.get( index );
 | 
			
		||||
        if( !(value instanceof String) )
 | 
			
		||||
        {
 | 
			
		||||
            throw LuaValues.badArgumentOf( index, "string", value );
 | 
			
		||||
        }
 | 
			
		||||
        Object value = get( index );
 | 
			
		||||
        if( !(value instanceof String) ) throw LuaValues.badArgumentOf( index, "string", value );
 | 
			
		||||
        return (String) value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a string argument as a byte array.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value. This is a <em>read only</em> buffer.
 | 
			
		||||
     * @throws LuaException If the value is not a string.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    default ByteBuffer getBytes( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return LuaValues.encode( getString( index ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a string argument as an enum value.
 | 
			
		||||
     *
 | 
			
		||||
@@ -182,7 +165,7 @@ public interface IArguments
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    default <T extends Enum<T>> T getEnum( int index, Class<T> klass ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return LuaValues.checkEnum( index, klass, this.getString( index ) );
 | 
			
		||||
        return LuaValues.checkEnum( index, klass, getString( index ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -195,24 +178,82 @@ public interface IArguments
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    default Map<?, ?> getTable( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = this.get( index );
 | 
			
		||||
        if( !(value instanceof Map) )
 | 
			
		||||
        {
 | 
			
		||||
            throw LuaValues.badArgumentOf( index, "table", value );
 | 
			
		||||
        }
 | 
			
		||||
        Object value = get( index );
 | 
			
		||||
        if( !(value instanceof Map) ) throw LuaValues.badArgumentOf( index, "table", value );
 | 
			
		||||
        return (Map<?, ?>) value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a string argument as a byte array.
 | 
			
		||||
     * Get an argument as a double.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value, or {@link Optional#empty()} if not present. This is a <em>read only</em> buffer.
 | 
			
		||||
     * @throws LuaException If the value is not a string.
 | 
			
		||||
     * @return The argument's value, or {@link Optional#empty()} if not present.
 | 
			
		||||
     * @throws LuaException If the value is not a number.
 | 
			
		||||
     */
 | 
			
		||||
    default Optional<ByteBuffer> optBytes( int index ) throws LuaException
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    default Optional<Double> optDouble( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return this.optString( index ).map( LuaValues::encode );
 | 
			
		||||
        Object value = get( index );
 | 
			
		||||
        if( value == null ) return Optional.empty();
 | 
			
		||||
        if( !(value instanceof Number) ) throw LuaValues.badArgumentOf( index, "number", value );
 | 
			
		||||
        return Optional.of( ((Number) value).doubleValue() );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as an int.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value, or {@link Optional#empty()} if not present.
 | 
			
		||||
     * @throws LuaException If the value is not a number.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    default Optional<Integer> optInt( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return optLong( index ).map( Long::intValue );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a long.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value, or {@link Optional#empty()} if not present.
 | 
			
		||||
     * @throws LuaException If the value is not a number.
 | 
			
		||||
     */
 | 
			
		||||
    default Optional<Long> optLong( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = get( index );
 | 
			
		||||
        if( value == null ) return Optional.empty();
 | 
			
		||||
        if( !(value instanceof Number) ) throw LuaValues.badArgumentOf( index, "number", value );
 | 
			
		||||
        return Optional.of( LuaValues.checkFiniteNum( index, (Number) value ).longValue() );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a finite number (not infinite or NaN).
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value, or {@link Optional#empty()} if not present.
 | 
			
		||||
     * @throws LuaException If the value is not finite.
 | 
			
		||||
     */
 | 
			
		||||
    default Optional<Double> optFiniteDouble( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Optional<Double> value = optDouble( index );
 | 
			
		||||
        if( value.isPresent() ) LuaValues.checkFiniteNum( index, value.get() );
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a boolean.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value, or {@link Optional#empty()} if not present.
 | 
			
		||||
     * @throws LuaException If the value is not a boolean.
 | 
			
		||||
     */
 | 
			
		||||
    default Optional<Boolean> optBoolean( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = get( index );
 | 
			
		||||
        if( value == null ) return Optional.empty();
 | 
			
		||||
        if( !(value instanceof Boolean) ) throw LuaValues.badArgumentOf( index, "boolean", value );
 | 
			
		||||
        return Optional.of( (Boolean) value );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -224,18 +265,24 @@ public interface IArguments
 | 
			
		||||
     */
 | 
			
		||||
    default Optional<String> optString( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = this.get( index );
 | 
			
		||||
        if( value == null )
 | 
			
		||||
        {
 | 
			
		||||
            return Optional.empty();
 | 
			
		||||
        }
 | 
			
		||||
        if( !(value instanceof String) )
 | 
			
		||||
        {
 | 
			
		||||
            throw LuaValues.badArgumentOf( index, "string", value );
 | 
			
		||||
        }
 | 
			
		||||
        Object value = get( index );
 | 
			
		||||
        if( value == null ) return Optional.empty();
 | 
			
		||||
        if( !(value instanceof String) ) throw LuaValues.badArgumentOf( index, "string", value );
 | 
			
		||||
        return Optional.of( (String) value );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a string argument as a byte array.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value, or {@link Optional#empty()} if not present. This is a <em>read only</em> buffer.
 | 
			
		||||
     * @throws LuaException If the value is not a string.
 | 
			
		||||
     */
 | 
			
		||||
    default Optional<ByteBuffer> optBytes( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return optString( index ).map( LuaValues::encode );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a string argument as an enum value.
 | 
			
		||||
     *
 | 
			
		||||
@@ -248,10 +295,25 @@ public interface IArguments
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    default <T extends Enum<T>> Optional<T> optEnum( int index, Class<T> klass ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Optional<String> str = this.optString( index );
 | 
			
		||||
        Optional<String> str = optString( index );
 | 
			
		||||
        return str.isPresent() ? Optional.of( LuaValues.checkEnum( index, klass, str.get() ) ) : Optional.empty();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a table.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value, or {@link Optional#empty()} if not present.
 | 
			
		||||
     * @throws LuaException If the value is not a table.
 | 
			
		||||
     */
 | 
			
		||||
    default Optional<Map<?, ?>> optTable( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = get( index );
 | 
			
		||||
        if( value == null ) return Optional.empty();
 | 
			
		||||
        if( !(value instanceof Map) ) throw LuaValues.badArgumentOf( index, "map", value );
 | 
			
		||||
        return Optional.of( (Map<?, ?>) value );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a double.
 | 
			
		||||
     *
 | 
			
		||||
@@ -262,29 +324,7 @@ public interface IArguments
 | 
			
		||||
     */
 | 
			
		||||
    default double optDouble( int index, double def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return this.optDouble( index ).orElse( def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a double.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value, or {@link Optional#empty()} if not present.
 | 
			
		||||
     * @throws LuaException If the value is not a number.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    default Optional<Double> optDouble( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = this.get( index );
 | 
			
		||||
        if( value == null )
 | 
			
		||||
        {
 | 
			
		||||
            return Optional.empty();
 | 
			
		||||
        }
 | 
			
		||||
        if( !(value instanceof Number) )
 | 
			
		||||
        {
 | 
			
		||||
            throw LuaValues.badArgumentOf( index, "number", value );
 | 
			
		||||
        }
 | 
			
		||||
        return Optional.of( ((Number) value).doubleValue() );
 | 
			
		||||
        return optDouble( index ).orElse( def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -297,42 +337,7 @@ public interface IArguments
 | 
			
		||||
     */
 | 
			
		||||
    default int optInt( int index, int def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return this.optInt( index ).orElse( def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as an int.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value, or {@link Optional#empty()} if not present.
 | 
			
		||||
     * @throws LuaException If the value is not a number.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    default Optional<Integer> optInt( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return this.optLong( index ).map( Long::intValue );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a long.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value, or {@link Optional#empty()} if not present.
 | 
			
		||||
     * @throws LuaException If the value is not a number.
 | 
			
		||||
     */
 | 
			
		||||
    default Optional<Long> optLong( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = this.get( index );
 | 
			
		||||
        if( value == null )
 | 
			
		||||
        {
 | 
			
		||||
            return Optional.empty();
 | 
			
		||||
        }
 | 
			
		||||
        if( !(value instanceof Number) )
 | 
			
		||||
        {
 | 
			
		||||
            throw LuaValues.badArgumentOf( index, "number", value );
 | 
			
		||||
        }
 | 
			
		||||
        return Optional.of( LuaValues.checkFiniteNum( index, (Number) value )
 | 
			
		||||
            .longValue() );
 | 
			
		||||
        return optInt( index ).orElse( def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -345,7 +350,7 @@ public interface IArguments
 | 
			
		||||
     */
 | 
			
		||||
    default long optLong( int index, long def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return this.optLong( index ).orElse( def );
 | 
			
		||||
        return optLong( index ).orElse( def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -358,24 +363,7 @@ public interface IArguments
 | 
			
		||||
     */
 | 
			
		||||
    default double optFiniteDouble( int index, double def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return this.optFiniteDouble( index ).orElse( def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a finite number (not infinite or NaN).
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value, or {@link Optional#empty()} if not present.
 | 
			
		||||
     * @throws LuaException If the value is not finite.
 | 
			
		||||
     */
 | 
			
		||||
    default Optional<Double> optFiniteDouble( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Optional<Double> value = this.optDouble( index );
 | 
			
		||||
        if( value.isPresent() )
 | 
			
		||||
        {
 | 
			
		||||
            LuaValues.checkFiniteNum( index, value.get() );
 | 
			
		||||
        }
 | 
			
		||||
        return value;
 | 
			
		||||
        return optFiniteDouble( index ).orElse( def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -388,28 +376,7 @@ public interface IArguments
 | 
			
		||||
     */
 | 
			
		||||
    default boolean optBoolean( int index, boolean def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return this.optBoolean( index ).orElse( def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a boolean.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value, or {@link Optional#empty()} if not present.
 | 
			
		||||
     * @throws LuaException If the value is not a boolean.
 | 
			
		||||
     */
 | 
			
		||||
    default Optional<Boolean> optBoolean( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = this.get( index );
 | 
			
		||||
        if( value == null )
 | 
			
		||||
        {
 | 
			
		||||
            return Optional.empty();
 | 
			
		||||
        }
 | 
			
		||||
        if( !(value instanceof Boolean) )
 | 
			
		||||
        {
 | 
			
		||||
            throw LuaValues.badArgumentOf( index, "boolean", value );
 | 
			
		||||
        }
 | 
			
		||||
        return Optional.of( (Boolean) value );
 | 
			
		||||
        return optBoolean( index ).orElse( def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -422,7 +389,7 @@ public interface IArguments
 | 
			
		||||
     */
 | 
			
		||||
    default String optString( int index, String def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return this.optString( index ).orElse( def );
 | 
			
		||||
        return optString( index ).orElse( def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -435,27 +402,6 @@ public interface IArguments
 | 
			
		||||
     */
 | 
			
		||||
    default Map<?, ?> optTable( int index, Map<Object, Object> def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return this.optTable( index ).orElse( def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a table.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index The argument number.
 | 
			
		||||
     * @return The argument's value, or {@link Optional#empty()} if not present.
 | 
			
		||||
     * @throws LuaException If the value is not a table.
 | 
			
		||||
     */
 | 
			
		||||
    default Optional<Map<?, ?>> optTable( int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = this.get( index );
 | 
			
		||||
        if( value == null )
 | 
			
		||||
        {
 | 
			
		||||
            return Optional.empty();
 | 
			
		||||
        }
 | 
			
		||||
        if( !(value instanceof Map) )
 | 
			
		||||
        {
 | 
			
		||||
            throw LuaValues.badArgumentOf( index, "map", value );
 | 
			
		||||
        }
 | 
			
		||||
        return Optional.of( (Map<?, ?>) value );
 | 
			
		||||
        return optTable( index ).orElse( def );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.filesystem.IFileSystem;
 | 
			
		||||
@@ -12,7 +11,8 @@ import dan200.computercraft.api.peripheral.IComputerAccess;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * An interface passed to {@link ILuaAPIFactory} in order to provide additional information about a computer.
 | 
			
		||||
 * An interface passed to {@link ILuaAPIFactory} in order to provide additional information
 | 
			
		||||
 * about a computer.
 | 
			
		||||
 */
 | 
			
		||||
public interface IComputerSystem extends IComputerAccess
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.peripheral.IDynamicPeripheral;
 | 
			
		||||
@@ -13,13 +12,15 @@ import javax.annotation.Nonnull;
 | 
			
		||||
/**
 | 
			
		||||
 * An interface for representing custom objects returned by peripherals or other Lua objects.
 | 
			
		||||
 *
 | 
			
		||||
 * Generally, one does not need to implement this type - it is sufficient to return an object with some methods annotated with {@link LuaFunction}. {@link
 | 
			
		||||
 * IDynamicLuaObject} is useful when you wish your available methods to change at runtime.
 | 
			
		||||
 * Generally, one does not need to implement this type - it is sufficient to return an object with some methods
 | 
			
		||||
 * annotated with {@link LuaFunction}. {@link IDynamicLuaObject} is useful when you wish your available methods to
 | 
			
		||||
 * change at runtime.
 | 
			
		||||
 */
 | 
			
		||||
public interface IDynamicLuaObject
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the names of the methods that this object implements. This should not change over the course of the object's lifetime.
 | 
			
		||||
     * Get the names of the methods that this object implements. This should not change over the course of the object's
 | 
			
		||||
     * lifetime.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The method names this object provides.
 | 
			
		||||
     * @see IDynamicPeripheral#getMethodNames()
 | 
			
		||||
@@ -30,10 +31,13 @@ public interface IDynamicLuaObject
 | 
			
		||||
    /**
 | 
			
		||||
     * Called when a user calls one of the methods that this object implements.
 | 
			
		||||
     *
 | 
			
		||||
     * @param context   The context of the currently running lua thread. This can be used to wait for events or otherwise yield.
 | 
			
		||||
     * @param method    An integer identifying which method index from {@link #getMethodNames()} the computer wishes to call.
 | 
			
		||||
     * @param context   The context of the currently running lua thread. This can be used to wait for events
 | 
			
		||||
     *                  or otherwise yield.
 | 
			
		||||
     * @param method    An integer identifying which method index from {@link #getMethodNames()} the computer wishes
 | 
			
		||||
     *                  to call.
 | 
			
		||||
     * @param arguments The arguments for this method.
 | 
			
		||||
     * @return The result of this function. Either an immediate value ({@link MethodResult#of(Object...)} or an instruction to yield.
 | 
			
		||||
     * @return The result of this function. Either an immediate value ({@link MethodResult#of(Object...)} or an
 | 
			
		||||
     * instruction to yield.
 | 
			
		||||
     * @throws LuaException If the function threw an exception.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
 
 | 
			
		||||
@@ -1,19 +1,18 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a Lua object which is stored as a global variable on computer startup. This must either provide {@link LuaFunction} annotated functions or
 | 
			
		||||
 * implement {@link IDynamicLuaObject}.
 | 
			
		||||
 * Represents a Lua object which is stored as a global variable on computer startup. This must either provide
 | 
			
		||||
 * {@link LuaFunction} annotated functions or implement {@link IDynamicLuaObject}.
 | 
			
		||||
 *
 | 
			
		||||
 * Before implementing this interface, consider alternative methods of providing methods. It is generally preferred to use peripherals to provide
 | 
			
		||||
 * functionality to users.
 | 
			
		||||
 * Before implementing this interface, consider alternative methods of providing methods. It is generally preferred
 | 
			
		||||
 * to use peripherals to provide functionality to users.
 | 
			
		||||
 *
 | 
			
		||||
 * @see ILuaAPIFactory
 | 
			
		||||
 * @see ComputerCraftAPI#registerAPIFactory(ILuaAPIFactory)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
@@ -18,7 +17,8 @@ public interface ILuaCallback
 | 
			
		||||
    /**
 | 
			
		||||
     * Resume this coroutine.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args The result of resuming this coroutine. These will have the same form as described in {@link LuaFunction}.
 | 
			
		||||
     * @param args The result of resuming this coroutine. These will have the same form as described in
 | 
			
		||||
     *             {@link LuaFunction}.
 | 
			
		||||
     * @return The result of this continuation. Either the result to return to the callee, or another yield.
 | 
			
		||||
     * @throws LuaException On an error.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -1,25 +1,25 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * An interface passed to peripherals and {@link IDynamicLuaObject}s by computers or turtles, providing methods that allow the peripheral call to interface
 | 
			
		||||
 * with the computer.
 | 
			
		||||
 * An interface passed to peripherals and {@link IDynamicLuaObject}s by computers or turtles, providing methods
 | 
			
		||||
 * that allow the peripheral call to interface with the computer.
 | 
			
		||||
 */
 | 
			
		||||
public interface ILuaContext
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Queue a task to be executed on the main server thread at the beginning of next tick, but do not wait for it to complete. This should be used when you
 | 
			
		||||
     * need to interact with the world in a thread-safe manner but do not care about the result or you wish to run asynchronously.
 | 
			
		||||
     * Queue a task to be executed on the main server thread at the beginning of next tick, but do not wait for it to
 | 
			
		||||
     * complete. This should be used when you need to interact with the world in a thread-safe manner but do not care
 | 
			
		||||
     * about the result or you wish to run asynchronously.
 | 
			
		||||
     *
 | 
			
		||||
     * When the task has finished, it will enqueue a {@code task_completed} event, which takes the task id, a success value and the return values, or an
 | 
			
		||||
     * error message if it failed.
 | 
			
		||||
     * When the task has finished, it will enqueue a {@code task_completed} event, which takes the task id, a success
 | 
			
		||||
     * value and the return values, or an error message if it failed.
 | 
			
		||||
     *
 | 
			
		||||
     * @param task The task to execute on the main thread.
 | 
			
		||||
     * @return The "id" of the task. This will be the first argument to the {@code task_completed} event.
 | 
			
		||||
@@ -27,4 +27,21 @@ public interface ILuaContext
 | 
			
		||||
     * @see LuaFunction#mainThread() To run functions on the main thread and return their results synchronously.
 | 
			
		||||
     */
 | 
			
		||||
    long issueMainThreadTask( @Nonnull ILuaTask task ) throws LuaException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Queue a task to be executed on the main server thread at the beginning of next tick, waiting for it to complete.
 | 
			
		||||
     * This should be used when you need to interact with the world in a thread-safe manner.
 | 
			
		||||
     *
 | 
			
		||||
     * Note that the return values of your task are handled as events, meaning more complex objects such as maps or
 | 
			
		||||
     * {@link IDynamicLuaObject} will not preserve their identities.
 | 
			
		||||
     *
 | 
			
		||||
     * @param task The task to execute on the main thread.
 | 
			
		||||
     * @return The objects returned by {@code task}.
 | 
			
		||||
     * @throws LuaException If the task could not be queued, or if the task threw an exception.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    default MethodResult executeMainThreadTask( @Nonnull ILuaTask task ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return TaskCallback.make( this, task );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,16 +1,15 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A function, which can be called from Lua. If you need to return a table of functions, it is recommended to use an object with {@link LuaFunction}
 | 
			
		||||
 * methods, or implement {@link IDynamicLuaObject}.
 | 
			
		||||
 * A function, which can be called from Lua. If you need to return a table of functions, it is recommended to use
 | 
			
		||||
 * an object with {@link LuaFunction} methods, or implement {@link IDynamicLuaObject}.
 | 
			
		||||
 *
 | 
			
		||||
 * @see MethodResult#of(Object)
 | 
			
		||||
 */
 | 
			
		||||
@@ -18,8 +17,8 @@ import javax.annotation.Nonnull;
 | 
			
		||||
public interface ILuaFunction
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Call this function with a series of arguments. Note, this will <em>always</em> be called on the computer thread, and so its implementation must be
 | 
			
		||||
     * thread-safe.
 | 
			
		||||
     * Call this function with a series of arguments. Note, this will <em>always</em> be called on the computer thread,
 | 
			
		||||
     * and so its implementation must be thread-safe.
 | 
			
		||||
     *
 | 
			
		||||
     * @param arguments The arguments for this function
 | 
			
		||||
     * @return The result of calling this function.
 | 
			
		||||
 
 | 
			
		||||
@@ -1,18 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
 | 
			
		||||
public interface ILuaObject
 | 
			
		||||
{
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    String[] getMethodNames();
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,16 +1,16 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A task which can be executed via {@link ILuaContext#issueMainThreadTask(ILuaTask)} This will be run on the main thread, at the beginning of the next
 | 
			
		||||
 * tick.
 | 
			
		||||
 * A task which can be executed via {@link ILuaContext#issueMainThreadTask(ILuaTask)} This will be run on the main
 | 
			
		||||
 * thread, at the beginning of the
 | 
			
		||||
 * next tick.
 | 
			
		||||
 *
 | 
			
		||||
 * @see ILuaContext#issueMainThreadTask(ILuaTask)
 | 
			
		||||
 */
 | 
			
		||||
@@ -21,8 +21,9 @@ public interface ILuaTask
 | 
			
		||||
     * Execute this task.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The arguments to add to the {@code task_completed} event.
 | 
			
		||||
     * @throws LuaException If you throw any exception from this function, a lua error will be raised with the same message as your exception. Use this
 | 
			
		||||
     *                      to throw appropriate errors if the wrong arguments are supplied to your method.
 | 
			
		||||
     * @throws LuaException If you throw any exception from this function, a lua error will be raised with the
 | 
			
		||||
     *                      same message as your exception. Use this to throw appropriate errors if the wrong
 | 
			
		||||
     *                      arguments are supplied to your method.
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    Object[] execute() throws LuaException;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
@@ -20,14 +19,14 @@ public class LuaException extends Exception
 | 
			
		||||
    public LuaException( @Nullable String message )
 | 
			
		||||
    {
 | 
			
		||||
        super( message );
 | 
			
		||||
        this.hasLevel = false;
 | 
			
		||||
        this.level = 1;
 | 
			
		||||
        hasLevel = false;
 | 
			
		||||
        level = 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public LuaException( @Nullable String message, int level )
 | 
			
		||||
    {
 | 
			
		||||
        super( message );
 | 
			
		||||
        this.hasLevel = true;
 | 
			
		||||
        hasLevel = true;
 | 
			
		||||
        this.level = level;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -38,16 +37,17 @@ public class LuaException extends Exception
 | 
			
		||||
     */
 | 
			
		||||
    public boolean hasLevel()
 | 
			
		||||
    {
 | 
			
		||||
        return this.hasLevel;
 | 
			
		||||
        return hasLevel;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The level this error is raised at. Level 1 is the function's caller, level 2 is that function's caller, and so on.
 | 
			
		||||
     * The level this error is raised at. Level 1 is the function's caller, level 2 is that function's caller, and so
 | 
			
		||||
     * on.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The level to raise the error at.
 | 
			
		||||
     */
 | 
			
		||||
    public int getLevel()
 | 
			
		||||
    {
 | 
			
		||||
        return this.level;
 | 
			
		||||
        return level;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.peripheral.IComputerAccess;
 | 
			
		||||
@@ -16,8 +15,8 @@ import java.util.Optional;
 | 
			
		||||
/**
 | 
			
		||||
 * Used to mark a Java function which is callable from Lua.
 | 
			
		||||
 *
 | 
			
		||||
 * Methods annotated with {@link LuaFunction} must be public final instance methods. They can have any number of parameters, but they must be of the
 | 
			
		||||
 * following types:
 | 
			
		||||
 * Methods annotated with {@link LuaFunction} must be public final instance methods. They can have any number of
 | 
			
		||||
 * parameters, but they must be of the following types:
 | 
			
		||||
 *
 | 
			
		||||
 * <ul>
 | 
			
		||||
 *   <li>{@link ILuaContext} (and {@link IComputerAccess} if on a {@link IPeripheral})</li>
 | 
			
		||||
@@ -49,7 +48,8 @@ public @interface LuaFunction
 | 
			
		||||
    String[] value() default {};
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Run this function on the main server thread. This should be specified for any method which interacts with Minecraft in a thread-unsafe manner.
 | 
			
		||||
     * Run this function on the main server thread. This should be specified for any method which interacts with
 | 
			
		||||
     * Minecraft in a thread-unsafe manner.
 | 
			
		||||
     *
 | 
			
		||||
     * @return Whether this functi
 | 
			
		||||
     * @see ILuaContext#issueMainThreadTask(ILuaTask)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
@@ -38,8 +37,41 @@ public final class LuaValues
 | 
			
		||||
            chars[i] = c < 256 ? (byte) c : 63;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ByteBuffer.wrap( chars )
 | 
			
		||||
            .asReadOnlyBuffer();
 | 
			
		||||
        return ByteBuffer.wrap( chars ).asReadOnlyBuffer();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns a more detailed representation of this number's type. If this is finite, it will just return "number",
 | 
			
		||||
     * otherwise it returns whether it is infinite or NaN.
 | 
			
		||||
     *
 | 
			
		||||
     * @param value The value to extract the type for.
 | 
			
		||||
     * @return This value's numeric type.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static String getNumericType( double value )
 | 
			
		||||
    {
 | 
			
		||||
        if( Double.isNaN( value ) ) return "nan";
 | 
			
		||||
        if( value == Double.POSITIVE_INFINITY ) return "inf";
 | 
			
		||||
        if( value == Double.NEGATIVE_INFINITY ) return "-inf";
 | 
			
		||||
        return "number";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a string representation of the given value's type.
 | 
			
		||||
     *
 | 
			
		||||
     * @param value The value whose type we are trying to compute.
 | 
			
		||||
     * @return A string representation of the given value's type, in a similar format to that provided by Lua's
 | 
			
		||||
     * {@code type} function.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static String getType( @Nullable Object value )
 | 
			
		||||
    {
 | 
			
		||||
        if( value == null ) return "nil";
 | 
			
		||||
        if( value instanceof String ) return "string";
 | 
			
		||||
        if( value instanceof Boolean ) return "boolean";
 | 
			
		||||
        if( value instanceof Number ) return "number";
 | 
			
		||||
        if( value instanceof Map ) return "table";
 | 
			
		||||
        return "userdata";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -70,38 +102,6 @@ public final class LuaValues
 | 
			
		||||
        return new LuaException( "bad argument #" + (index + 1) + " (" + expected + " expected, got " + actual + ")" );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a string representation of the given value's type.
 | 
			
		||||
     *
 | 
			
		||||
     * @param value The value whose type we are trying to compute.
 | 
			
		||||
     * @return A string representation of the given value's type, in a similar format to that provided by Lua's {@code type} function.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static String getType( @Nullable Object value )
 | 
			
		||||
    {
 | 
			
		||||
        if( value == null )
 | 
			
		||||
        {
 | 
			
		||||
            return "nil";
 | 
			
		||||
        }
 | 
			
		||||
        if( value instanceof String )
 | 
			
		||||
        {
 | 
			
		||||
            return "string";
 | 
			
		||||
        }
 | 
			
		||||
        if( value instanceof Boolean )
 | 
			
		||||
        {
 | 
			
		||||
            return "boolean";
 | 
			
		||||
        }
 | 
			
		||||
        if( value instanceof Number )
 | 
			
		||||
        {
 | 
			
		||||
            return "number";
 | 
			
		||||
        }
 | 
			
		||||
        if( value instanceof Map )
 | 
			
		||||
        {
 | 
			
		||||
            return "table";
 | 
			
		||||
        }
 | 
			
		||||
        return "userdata";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Ensure a numeric argument is finite (i.e. not infinite or {@link Double#NaN}.
 | 
			
		||||
     *
 | 
			
		||||
@@ -126,38 +126,10 @@ public final class LuaValues
 | 
			
		||||
     */
 | 
			
		||||
    public static double checkFinite( int index, double value ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( !Double.isFinite( value ) )
 | 
			
		||||
        {
 | 
			
		||||
            throw badArgument( index, "number", getNumericType( value ) );
 | 
			
		||||
        }
 | 
			
		||||
        if( !Double.isFinite( value ) ) throw badArgument( index, "number", getNumericType( value ) );
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns a more detailed representation of this number's type. If this is finite, it will just return "number", otherwise it returns whether it is
 | 
			
		||||
     * infinite or NaN.
 | 
			
		||||
     *
 | 
			
		||||
     * @param value The value to extract the type for.
 | 
			
		||||
     * @return This value's numeric type.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static String getNumericType( double value )
 | 
			
		||||
    {
 | 
			
		||||
        if( Double.isNaN( value ) )
 | 
			
		||||
        {
 | 
			
		||||
            return "nan";
 | 
			
		||||
        }
 | 
			
		||||
        if( value == Double.POSITIVE_INFINITY )
 | 
			
		||||
        {
 | 
			
		||||
            return "inf";
 | 
			
		||||
        }
 | 
			
		||||
        if( value == Double.NEGATIVE_INFINITY )
 | 
			
		||||
        {
 | 
			
		||||
            return "-inf";
 | 
			
		||||
        }
 | 
			
		||||
        return "number";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Ensure a string is a valid enum value.
 | 
			
		||||
     *
 | 
			
		||||
@@ -172,11 +144,7 @@ public final class LuaValues
 | 
			
		||||
    {
 | 
			
		||||
        for( T possibility : klass.getEnumConstants() )
 | 
			
		||||
        {
 | 
			
		||||
            if( possibility.name()
 | 
			
		||||
                .equalsIgnoreCase( value ) )
 | 
			
		||||
            {
 | 
			
		||||
                return possibility;
 | 
			
		||||
            }
 | 
			
		||||
            if( possibility.name().equalsIgnoreCase( value ) ) return possibility;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        throw new LuaException( "bad argument #" + (index + 1) + " (unknown option " + value + ")" );
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.peripheral.IComputerAccess;
 | 
			
		||||
@@ -18,8 +17,8 @@ import java.util.Objects;
 | 
			
		||||
/**
 | 
			
		||||
 * The result of invoking a Lua method.
 | 
			
		||||
 *
 | 
			
		||||
 * Method results either return a value immediately ({@link #of(Object...)} or yield control to the parent coroutine. When the current coroutine is resumed,
 | 
			
		||||
 * we invoke the provided {@link ILuaCallback#resume(Object[])} callback.
 | 
			
		||||
 * Method results either return a value immediately ({@link #of(Object...)} or yield control to the parent coroutine.
 | 
			
		||||
 * When the current coroutine is resumed, we invoke the provided {@link ILuaCallback#resume(Object[])} callback.
 | 
			
		||||
 */
 | 
			
		||||
public final class MethodResult
 | 
			
		||||
{
 | 
			
		||||
@@ -31,14 +30,14 @@ public final class MethodResult
 | 
			
		||||
 | 
			
		||||
    private MethodResult( Object[] arguments, ILuaCallback callback )
 | 
			
		||||
    {
 | 
			
		||||
        this.result = arguments;
 | 
			
		||||
        result = arguments;
 | 
			
		||||
        this.callback = callback;
 | 
			
		||||
        this.adjust = 0;
 | 
			
		||||
        adjust = 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private MethodResult( Object[] arguments, ILuaCallback callback, int adjust )
 | 
			
		||||
    {
 | 
			
		||||
        this.result = arguments;
 | 
			
		||||
        result = arguments;
 | 
			
		||||
        this.callback = callback;
 | 
			
		||||
        this.adjust = adjust;
 | 
			
		||||
    }
 | 
			
		||||
@@ -57,11 +56,12 @@ public final class MethodResult
 | 
			
		||||
    /**
 | 
			
		||||
     * Return a single value immediately.
 | 
			
		||||
     *
 | 
			
		||||
     * Integers, doubles, floats, strings, booleans, {@link Map}, {@link Collection}s, arrays and {@code null} will be converted to their corresponding Lua
 | 
			
		||||
     * type. {@code byte[]} and {@link ByteBuffer} will be treated as binary strings. {@link ILuaFunction} will be treated as a function.
 | 
			
		||||
     * Integers, doubles, floats, strings, booleans, {@link Map}, {@link Collection}s, arrays and {@code null} will be
 | 
			
		||||
     * converted to their corresponding Lua type. {@code byte[]} and {@link ByteBuffer} will be treated as binary
 | 
			
		||||
     * strings. {@link ILuaFunction} will be treated as a function.
 | 
			
		||||
     *
 | 
			
		||||
     * In order to provide a custom object with methods, one may return a {@link IDynamicLuaObject}, or an arbitrary class with {@link LuaFunction}
 | 
			
		||||
     * annotations. Anything else will be converted to {@code nil}.
 | 
			
		||||
     * In order to provide a custom object with methods, one may return a {@link IDynamicLuaObject}, or an arbitrary
 | 
			
		||||
     * class with {@link LuaFunction} annotations. Anything else will be converted to {@code nil}.
 | 
			
		||||
     *
 | 
			
		||||
     * @param value The value to return to the calling Lua function.
 | 
			
		||||
     * @return A method result which returns immediately with the given value.
 | 
			
		||||
@@ -85,8 +85,8 @@ public final class MethodResult
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Wait for an event to occur on the computer, suspending the thread until it arises. This method is exactly equivalent to {@code os.pullEvent()} in
 | 
			
		||||
     * lua.
 | 
			
		||||
     * Wait for an event to occur on the computer, suspending the thread until it arises. This method is exactly
 | 
			
		||||
     * equivalent to {@code os.pullEvent()} in lua.
 | 
			
		||||
     *
 | 
			
		||||
     * @param filter   A specific event to wait for, or null to wait for any event.
 | 
			
		||||
     * @param callback The callback to resume with the name of the event that occurred, and any event parameters.
 | 
			
		||||
@@ -98,17 +98,15 @@ public final class MethodResult
 | 
			
		||||
    {
 | 
			
		||||
        Objects.requireNonNull( callback, "callback cannot be null" );
 | 
			
		||||
        return new MethodResult( new Object[] { filter }, results -> {
 | 
			
		||||
            if( results.length >= 1 && results[0].equals( "terminate" ) )
 | 
			
		||||
            {
 | 
			
		||||
                throw new LuaException( "Terminated", 0 );
 | 
			
		||||
            }
 | 
			
		||||
            if( results.length >= 1 && results[0].equals( "terminate" ) ) throw new LuaException( "Terminated", 0 );
 | 
			
		||||
            return callback.resume( results );
 | 
			
		||||
        } );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The same as {@link #pullEvent(String, ILuaCallback)}, except "terminated" events are ignored. Only use this if you want to prevent program
 | 
			
		||||
     * termination, which is not recommended. This method is exactly equivalent to {@code os.pullEventRaw()} in Lua.
 | 
			
		||||
     * The same as {@link #pullEvent(String, ILuaCallback)}, except "terminated" events are ignored. Only use this if
 | 
			
		||||
     * you want to prevent program termination, which is not recommended. This method is exactly equivalent to
 | 
			
		||||
     * {@code os.pullEventRaw()} in Lua.
 | 
			
		||||
     *
 | 
			
		||||
     * @param filter   A specific event to wait for, or null to wait for any event.
 | 
			
		||||
     * @param callback The callback to resume with the name of the event that occurred, and any event parameters.
 | 
			
		||||
@@ -123,8 +121,8 @@ public final class MethodResult
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to {@code coroutine.yield()} in lua. Use
 | 
			
		||||
     * {@code pullEvent()} if you wish to wait for events.
 | 
			
		||||
     * Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to
 | 
			
		||||
     * {@code coroutine.yield()} in lua. Use {@code pullEvent()} if you wish to wait for events.
 | 
			
		||||
     *
 | 
			
		||||
     * @param arguments An object array containing the arguments to pass to coroutine.yield()
 | 
			
		||||
     * @param callback  The callback to resume with an array containing the return values from coroutine.yield()
 | 
			
		||||
@@ -141,22 +139,23 @@ public final class MethodResult
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public Object[] getResult()
 | 
			
		||||
    {
 | 
			
		||||
        return this.result;
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public ILuaCallback getCallback()
 | 
			
		||||
    {
 | 
			
		||||
        return this.callback;
 | 
			
		||||
        return callback;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getErrorAdjust()
 | 
			
		||||
    {
 | 
			
		||||
        return this.adjust;
 | 
			
		||||
        return adjust;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Increase the Lua error by a specific amount. One should never need to use this function - it largely exists for some CC internal code.
 | 
			
		||||
     * Increase the Lua error by a specific amount. One should never need to use this function - it largely exists for
 | 
			
		||||
     * some CC internal code.
 | 
			
		||||
     *
 | 
			
		||||
     * @param adjust The amount to increase the level by.
 | 
			
		||||
     * @return The new {@link MethodResult} with an adjusted error. This has no effect on immediate results.
 | 
			
		||||
@@ -164,14 +163,8 @@ public final class MethodResult
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public MethodResult adjustError( int adjust )
 | 
			
		||||
    {
 | 
			
		||||
        if( adjust < 0 )
 | 
			
		||||
        {
 | 
			
		||||
            throw new IllegalArgumentException( "cannot adjust by a negative amount" );
 | 
			
		||||
        }
 | 
			
		||||
        if( adjust == 0 || this.callback == null )
 | 
			
		||||
        {
 | 
			
		||||
            return this;
 | 
			
		||||
        }
 | 
			
		||||
        return new MethodResult( this.result, this.callback, this.adjust + adjust );
 | 
			
		||||
        if( adjust < 0 ) throw new IllegalArgumentException( "cannot adjust by a negative amount" );
 | 
			
		||||
        if( adjust == 0 || callback == null ) return this;
 | 
			
		||||
        return new MethodResult( result, callback, this.adjust + adjust );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
@@ -36,41 +35,32 @@ public final class ObjectArguments implements IArguments
 | 
			
		||||
        this.args = Objects.requireNonNull( args );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public IArguments drop( int count )
 | 
			
		||||
    {
 | 
			
		||||
        if( count < 0 )
 | 
			
		||||
        {
 | 
			
		||||
            throw new IllegalStateException( "count cannot be negative" );
 | 
			
		||||
        }
 | 
			
		||||
        if( count == 0 )
 | 
			
		||||
        {
 | 
			
		||||
            return this;
 | 
			
		||||
        }
 | 
			
		||||
        if( count >= this.args.size() )
 | 
			
		||||
        {
 | 
			
		||||
            return EMPTY;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return new ObjectArguments( this.args.subList( count, this.args.size() ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Object[] getAll()
 | 
			
		||||
    {
 | 
			
		||||
        return this.args.toArray();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int count()
 | 
			
		||||
    {
 | 
			
		||||
        return this.args.size();
 | 
			
		||||
        return args.size();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public IArguments drop( int count )
 | 
			
		||||
    {
 | 
			
		||||
        if( count < 0 ) throw new IllegalStateException( "count cannot be negative" );
 | 
			
		||||
        if( count == 0 ) return this;
 | 
			
		||||
        if( count >= args.size() ) return EMPTY;
 | 
			
		||||
 | 
			
		||||
        return new ObjectArguments( args.subList( count, args.size() ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    @Override
 | 
			
		||||
    public Object get( int index )
 | 
			
		||||
    {
 | 
			
		||||
        return index >= this.args.size() ? null : this.args.get( index );
 | 
			
		||||
        return index >= args.size() ? null : args.get( index );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Object[] getAll()
 | 
			
		||||
    {
 | 
			
		||||
        return args.toArray();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										53
									
								
								src/main/java/dan200/computercraft/api/lua/TaskCallback.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								src/main/java/dan200/computercraft/api/lua/TaskCallback.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
 | 
			
		||||
final class TaskCallback implements ILuaCallback
 | 
			
		||||
{
 | 
			
		||||
    private final MethodResult pull = MethodResult.pullEvent( "task_complete", this );
 | 
			
		||||
    private final long task;
 | 
			
		||||
 | 
			
		||||
    private TaskCallback( long task )
 | 
			
		||||
    {
 | 
			
		||||
        this.task = task;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @Override
 | 
			
		||||
    public MethodResult resume( Object[] response ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( response.length < 3 || !(response[1] instanceof Number) || !(response[2] instanceof Boolean) )
 | 
			
		||||
        {
 | 
			
		||||
            return pull;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if( ((Number) response[1]).longValue() != task ) return pull;
 | 
			
		||||
 | 
			
		||||
        if( (Boolean) response[2] )
 | 
			
		||||
        {
 | 
			
		||||
            // Extract the return values from the event and return them
 | 
			
		||||
            return MethodResult.of( Arrays.copyOfRange( response, 3, response.length ) );
 | 
			
		||||
        }
 | 
			
		||||
        else if( response.length >= 4 && response[3] instanceof String )
 | 
			
		||||
        {
 | 
			
		||||
            // Extract the error message from the event and raise it
 | 
			
		||||
            throw new LuaException( (String) response[3] );
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            throw new LuaException( "error" );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static MethodResult make( ILuaContext context, ILuaTask func ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        long task = context.issueMainThreadTask( func );
 | 
			
		||||
        return new TaskCallback( task ).pull;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,16 +1,15 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.media;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.filesystem.IMount;
 | 
			
		||||
import net.minecraft.item.Item;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraft.sound.SoundEvent;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
import net.minecraft.sounds.SoundEvent;
 | 
			
		||||
import net.minecraft.world.item.Item;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import net.minecraft.world.level.Level;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
@@ -18,7 +17,8 @@ import javax.annotation.Nullable;
 | 
			
		||||
/**
 | 
			
		||||
 * Represents an item that can be placed in a disk drive and used by a Computer.
 | 
			
		||||
 *
 | 
			
		||||
 * Implement this interface on your {@link Item} class to allow it to be used in the drive. Alternatively, register a {@link IMediaProvider}.
 | 
			
		||||
 * Implement this interface on your {@link Item} class to allow it to be used in the drive. Alternatively, register
 | 
			
		||||
 * a {@link IMediaProvider}.
 | 
			
		||||
 */
 | 
			
		||||
public interface IMedia
 | 
			
		||||
{
 | 
			
		||||
@@ -44,7 +44,8 @@ public interface IMedia
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * If this disk represents an item with audio (like a record), get the readable name of the audio track. ie: "Jonathan Coulton - Still Alive"
 | 
			
		||||
     * If this disk represents an item with audio (like a record), get the readable name of the audio track. ie:
 | 
			
		||||
     * "Jonathan Coulton - Still Alive"
 | 
			
		||||
     *
 | 
			
		||||
     * @param stack The {@link ItemStack} to modify.
 | 
			
		||||
     * @return The name, or null if this item does not represent an item with audio.
 | 
			
		||||
@@ -68,20 +69,20 @@ public interface IMedia
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * If this disk represents an item with data (like a floppy disk), get a mount representing it's contents. This will be mounted onto the filesystem of
 | 
			
		||||
     * the computer while the media is in the disk drive.
 | 
			
		||||
     * If this disk represents an item with data (like a floppy disk), get a mount representing it's contents. This will
 | 
			
		||||
     * be mounted onto the filesystem of the computer while the media is in the disk drive.
 | 
			
		||||
     *
 | 
			
		||||
     * @param stack The {@link ItemStack} to modify.
 | 
			
		||||
     * @param world The world in which the item and disk drive reside.
 | 
			
		||||
     * @return The mount, or null if this item does not represent an item with data. If the mount returned also implements {@link
 | 
			
		||||
     * dan200.computercraft.api.filesystem.IWritableMount}, it will mounted using mountWritable()
 | 
			
		||||
     * @return The mount, or null if this item does not represent an item with data. If the mount returned also
 | 
			
		||||
     * implements {@link dan200.computercraft.api.filesystem.IWritableMount}, it will mounted using mountWritable()
 | 
			
		||||
     * @see IMount
 | 
			
		||||
     * @see dan200.computercraft.api.filesystem.IWritableMount
 | 
			
		||||
     * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String, long)
 | 
			
		||||
     * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(Level, String, long)
 | 
			
		||||
     * @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(String, String)
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    default IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world )
 | 
			
		||||
    default IMount createDataMount( @Nonnull ItemStack stack, @Nonnull Level world )
 | 
			
		||||
    {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,11 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.media;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.network;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
@@ -38,8 +37,8 @@ public interface IPacketNetwork
 | 
			
		||||
    boolean isWireless();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Submit a packet for transmitting across the network. This will route the packet through the network, sending it to all receivers within range (or any
 | 
			
		||||
     * interdimensional ones).
 | 
			
		||||
     * Submit a packet for transmitting across the network. This will route the packet through the network, sending it
 | 
			
		||||
     * to all receivers within range (or any interdimensional ones).
 | 
			
		||||
     *
 | 
			
		||||
     * @param packet The packet to send.
 | 
			
		||||
     * @param range  The maximum distance this packet will be sent.
 | 
			
		||||
@@ -49,8 +48,8 @@ public interface IPacketNetwork
 | 
			
		||||
    void transmitSameDimension( @Nonnull Packet packet, double range );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Submit a packet for transmitting across the network. This will route the packet through the network, sending it to all receivers across all
 | 
			
		||||
     * dimensions.
 | 
			
		||||
     * Submit a packet for transmitting across the network. This will route the packet through the network, sending it
 | 
			
		||||
     * to all receivers across all dimensions.
 | 
			
		||||
     *
 | 
			
		||||
     * @param packet The packet to send.
 | 
			
		||||
     * @see #transmitSameDimension(Packet, double)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,12 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.network;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.util.math.Vec3d;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
import net.minecraft.world.level.Level;
 | 
			
		||||
import net.minecraft.world.phys.Vec3;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
@@ -22,7 +21,7 @@ public interface IPacketReceiver
 | 
			
		||||
     * @return The receivers's world.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    World getWorld();
 | 
			
		||||
    Level getLevel();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the position in the world at which this receiver exists.
 | 
			
		||||
@@ -30,13 +29,14 @@ public interface IPacketReceiver
 | 
			
		||||
     * @return The receiver's position.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    Vec3d getPosition();
 | 
			
		||||
    Vec3 getPosition();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the maximum distance this receiver can send and receive messages.
 | 
			
		||||
     *
 | 
			
		||||
     * When determining whether a receiver can receive a message, the largest distance of the packet and receiver is used - ensuring it is within range. If
 | 
			
		||||
     * the packet or receiver is inter-dimensional, then the packet will always be received.
 | 
			
		||||
     * When determining whether a receiver can receive a message, the largest distance of the packet and receiver is
 | 
			
		||||
     * used - ensuring it is within range. If the packet or receiver is inter-dimensional, then the packet will always
 | 
			
		||||
     * be received.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The maximum distance this device can send and receive messages.
 | 
			
		||||
     * @see #isInterdimensional()
 | 
			
		||||
@@ -60,8 +60,8 @@ public interface IPacketReceiver
 | 
			
		||||
    /**
 | 
			
		||||
     * Receive a network packet from the same dimension.
 | 
			
		||||
     *
 | 
			
		||||
     * @param packet   The packet to receive. Generally you should check that you are listening on the given channel and, if so, queue the appropriate
 | 
			
		||||
     *                 modem event.
 | 
			
		||||
     * @param packet   The packet to receive. Generally you should check that you are listening on the given channel and,
 | 
			
		||||
     *                 if so, queue the appropriate modem event.
 | 
			
		||||
     * @param distance The distance this packet has travelled from the source.
 | 
			
		||||
     * @see Packet
 | 
			
		||||
     * @see #getRange()
 | 
			
		||||
@@ -73,8 +73,8 @@ public interface IPacketReceiver
 | 
			
		||||
    /**
 | 
			
		||||
     * Receive a network packet from a different dimension.
 | 
			
		||||
     *
 | 
			
		||||
     * @param packet The packet to receive. Generally you should check that you are listening on the given channel and, if so, queue the appropriate
 | 
			
		||||
     *               modem event.
 | 
			
		||||
     * @param packet The packet to receive. Generally you should check that you are listening on the given channel and,
 | 
			
		||||
     *               if so, queue the appropriate modem event.
 | 
			
		||||
     * @see Packet
 | 
			
		||||
     * @see IPacketNetwork#transmitInterdimensional(Packet)
 | 
			
		||||
     * @see IPacketNetwork#transmitSameDimension(Packet, double)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,12 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.network;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.util.math.Vec3d;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
import net.minecraft.world.level.Level;
 | 
			
		||||
import net.minecraft.world.phys.Vec3;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
@@ -22,7 +21,7 @@ public interface IPacketSender
 | 
			
		||||
     * @return The sender's world.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    World getWorld();
 | 
			
		||||
    Level getLevel();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the position in the world at which this sender exists.
 | 
			
		||||
@@ -30,11 +29,11 @@ public interface IPacketSender
 | 
			
		||||
     * @return The sender's position.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    Vec3d getPosition();
 | 
			
		||||
    Vec3 getPosition();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get some sort of identification string for this sender. This does not strictly need to be unique, but you should be able to extract some identifiable
 | 
			
		||||
     * information from it.
 | 
			
		||||
     * Get some sort of identification string for this sender. This does not strictly need to be unique, but you
 | 
			
		||||
     * should be able to extract some identifiable information from it.
 | 
			
		||||
     *
 | 
			
		||||
     * @return This device's id.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -1,130 +1,30 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.network;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents a packet which may be sent across a {@link IPacketNetwork}.
 | 
			
		||||
 *
 | 
			
		||||
 * @param channel      The channel to send the packet along. Receiving devices should only process packets from on
 | 
			
		||||
 *                     channels they are listening to.
 | 
			
		||||
 * @param replyChannel The channel to reply on.
 | 
			
		||||
 * @param payload      The contents of this packet. This should be a "valid" Lua object, safe for queuing as an
 | 
			
		||||
 *                     event or returning from a peripheral call.
 | 
			
		||||
 * @param sender       The object which sent this packet.
 | 
			
		||||
 * @see IPacketSender
 | 
			
		||||
 * @see IPacketNetwork#transmitSameDimension(Packet, double)
 | 
			
		||||
 * @see IPacketNetwork#transmitInterdimensional(Packet)
 | 
			
		||||
 * @see IPacketReceiver#receiveDifferentDimension(Packet)
 | 
			
		||||
 * @see IPacketReceiver#receiveSameDimension(Packet, double)
 | 
			
		||||
 */
 | 
			
		||||
public class Packet
 | 
			
		||||
public record Packet(
 | 
			
		||||
    int channel,
 | 
			
		||||
    int replyChannel,
 | 
			
		||||
    Object payload,
 | 
			
		||||
    IPacketSender sender
 | 
			
		||||
)
 | 
			
		||||
{
 | 
			
		||||
    private final int channel;
 | 
			
		||||
    private final int replyChannel;
 | 
			
		||||
    private final Object payload;
 | 
			
		||||
 | 
			
		||||
    private final IPacketSender sender;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new packet, ready for transmitting across the network.
 | 
			
		||||
     *
 | 
			
		||||
     * @param channel      The channel to send the packet along. Receiving devices should only process packets from on channels they are listening to.
 | 
			
		||||
     * @param replyChannel The channel to reply on.
 | 
			
		||||
     * @param payload      The contents of this packet. This should be a "valid" Lua object, safe for queuing as an event or returning from a peripheral
 | 
			
		||||
     *                     call.
 | 
			
		||||
     * @param sender       The object which sent this packet.
 | 
			
		||||
     */
 | 
			
		||||
    public Packet( int channel, int replyChannel, @Nullable Object payload, @Nonnull IPacketSender sender )
 | 
			
		||||
    {
 | 
			
		||||
        Objects.requireNonNull( sender, "sender cannot be null" );
 | 
			
		||||
 | 
			
		||||
        this.channel = channel;
 | 
			
		||||
        this.replyChannel = replyChannel;
 | 
			
		||||
        this.payload = payload;
 | 
			
		||||
        this.sender = sender;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the channel this packet is sent along. Receivers should generally only process packets from on channels they are listening to.
 | 
			
		||||
     *
 | 
			
		||||
     * @return This packet's channel.
 | 
			
		||||
     */
 | 
			
		||||
    public int getChannel()
 | 
			
		||||
    {
 | 
			
		||||
        return this.channel;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The channel to reply on. Objects which will reply should send it along this channel.
 | 
			
		||||
     *
 | 
			
		||||
     * @return This channel to reply on.
 | 
			
		||||
     */
 | 
			
		||||
    public int getReplyChannel()
 | 
			
		||||
    {
 | 
			
		||||
        return this.replyChannel;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The actual data of this packet. This should be a "valid" Lua object, safe for queuing as an event or returning from a peripheral call.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The packet's payload
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public Object getPayload()
 | 
			
		||||
    {
 | 
			
		||||
        return this.payload;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The object which sent this message.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The sending object.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public IPacketSender getSender()
 | 
			
		||||
    {
 | 
			
		||||
        return this.sender;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int hashCode()
 | 
			
		||||
    {
 | 
			
		||||
        int result;
 | 
			
		||||
        result = this.channel;
 | 
			
		||||
        result = 31 * result + this.replyChannel;
 | 
			
		||||
        result = 31 * result + (this.payload != null ? this.payload.hashCode() : 0);
 | 
			
		||||
        result = 31 * result + this.sender.hashCode();
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean equals( Object o )
 | 
			
		||||
    {
 | 
			
		||||
        if( this == o )
 | 
			
		||||
        {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if( o == null || this.getClass() != o.getClass() )
 | 
			
		||||
        {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Packet packet = (Packet) o;
 | 
			
		||||
 | 
			
		||||
        if( this.channel != packet.channel )
 | 
			
		||||
        {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        if( this.replyChannel != packet.replyChannel )
 | 
			
		||||
        {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        if( !Objects.equals( this.payload, packet.payload ) )
 | 
			
		||||
        {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        return this.sender.equals( packet.sender );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.network.wired;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI;
 | 
			
		||||
@@ -13,16 +12,18 @@ import javax.annotation.Nonnull;
 | 
			
		||||
/**
 | 
			
		||||
 * An object which may be part of a wired network.
 | 
			
		||||
 *
 | 
			
		||||
 * Elements should construct a node using {@link ComputerCraftAPI#createWiredNodeForElement(IWiredElement)}. This acts as a proxy for all network objects.
 | 
			
		||||
 * Whilst the node may change networks, an element's node should remain constant for its lifespan.
 | 
			
		||||
 * Elements should construct a node using {@link ComputerCraftAPI#createWiredNodeForElement(IWiredElement)}. This acts
 | 
			
		||||
 * as a proxy for all network objects. Whilst the node may change networks, an element's node should remain constant
 | 
			
		||||
 * for its lifespan.
 | 
			
		||||
 *
 | 
			
		||||
 * Elements are generally tied to a block or tile entity in world. In such as case, one should provide the {@link IWiredElement} capability for the
 | 
			
		||||
 * appropriate sides.
 | 
			
		||||
 * Elements are generally tied to a block or tile entity in world. In such as case, one should provide the
 | 
			
		||||
 * {@link IWiredElement} capability for the appropriate sides.
 | 
			
		||||
 */
 | 
			
		||||
public interface IWiredElement extends IWiredSender
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Called when objects on the network change. This may occur when network nodes are added or removed, or when peripherals change.
 | 
			
		||||
     * Called when objects on the network change. This may occur when network nodes are added or removed, or when
 | 
			
		||||
     * peripherals change.
 | 
			
		||||
     *
 | 
			
		||||
     * @param change The change which occurred.
 | 
			
		||||
     * @see IWiredNetworkChange
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.network.wired;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheral;
 | 
			
		||||
@@ -12,14 +11,16 @@ import javax.annotation.Nonnull;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A wired network is composed of one of more {@link IWiredNode}s, a set of connections between them, and a series of peripherals.
 | 
			
		||||
 * A wired network is composed of one of more {@link IWiredNode}s, a set of connections between them, and a series
 | 
			
		||||
 * of peripherals.
 | 
			
		||||
 *
 | 
			
		||||
 * 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 IWiredNetwork} will automatically handle the merging and splitting of networks (and thus changing of
 | 
			
		||||
 * available nodes and peripherals) as connections change.
 | 
			
		||||
 * 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 IWiredNetwork} will automatically
 | 
			
		||||
 * handle the merging and splitting of networks (and thus changing of available nodes and peripherals) as connections
 | 
			
		||||
 * change.
 | 
			
		||||
 *
 | 
			
		||||
 * 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 IWiredNode}.
 | 
			
		||||
 * 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 IWiredNode}.
 | 
			
		||||
 *
 | 
			
		||||
 * @see IWiredNode#getNetwork()
 | 
			
		||||
 */
 | 
			
		||||
@@ -58,10 +59,12 @@ public interface IWiredNetwork
 | 
			
		||||
    /**
 | 
			
		||||
     * Sever all connections this node has, removing it from this network.
 | 
			
		||||
     *
 | 
			
		||||
     * This should only be used on the server thread. You should only call this on nodes that your network element owns.
 | 
			
		||||
     * 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.
 | 
			
		||||
     * @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 IWiredNode#remove()
 | 
			
		||||
     */
 | 
			
		||||
@@ -70,7 +73,8 @@ public interface IWiredNetwork
 | 
			
		||||
    /**
 | 
			
		||||
     * Update the peripherals a node provides.
 | 
			
		||||
     *
 | 
			
		||||
     * This should only be used on the server thread. You should only call this on nodes that your network element owns.
 | 
			
		||||
     * 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.
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.network.wired;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheral;
 | 
			
		||||
@@ -19,8 +18,8 @@ import java.util.Map;
 | 
			
		||||
public interface IWiredNetworkChange
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * A set of peripherals which have been removed. Note that there may be entries with the same name in the added and removed set, but with a different
 | 
			
		||||
     * peripheral.
 | 
			
		||||
     * A set of peripherals which have been removed. Note that there may be entries with the same name
 | 
			
		||||
     * in the added and removed set, but with a different peripheral.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The set of removed peripherals.
 | 
			
		||||
     */
 | 
			
		||||
@@ -28,8 +27,8 @@ public interface IWiredNetworkChange
 | 
			
		||||
    Map<String, IPeripheral> peripheralsRemoved();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * A set of peripherals which have been added. Note that there may be entries with the same name in the added and removed set, but with a different
 | 
			
		||||
     * peripheral.
 | 
			
		||||
     * A set of peripherals which have been added. Note that there may be entries with the same name
 | 
			
		||||
     * in the added and removed set, but with a different peripheral.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The set of added peripherals.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.network.wired;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.network.IPacketNetwork;
 | 
			
		||||
@@ -15,14 +14,15 @@ import java.util.Map;
 | 
			
		||||
/**
 | 
			
		||||
 * Wired nodes act as a layer between {@link IWiredElement}s and {@link IWiredNetwork}s.
 | 
			
		||||
 *
 | 
			
		||||
 * 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.
 | 
			
		||||
 * 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.
 | 
			
		||||
 *
 | 
			
		||||
 * When sending a packet, the system will attempt to find the shortest path between the two nodes based on their element's position. Note that packet
 | 
			
		||||
 * senders and receivers can have different locations from their associated element: the distance between the two will be added to the total packet's
 | 
			
		||||
 * distance.
 | 
			
		||||
 * When sending a packet, the system will attempt to find the shortest path between the two nodes based on their
 | 
			
		||||
 * element's position. Note that packet senders and receivers can have different locations from their associated
 | 
			
		||||
 * element: the distance between the two will be added to the total packet's distance.
 | 
			
		||||
 *
 | 
			
		||||
 * Wired nodes also provide several convenience methods for interacting with a wired network. These should only ever be used on the main server thread.
 | 
			
		||||
 * Wired nodes also provide several convenience methods for interacting with a wired network. These should only ever
 | 
			
		||||
 * be used on the main server thread.
 | 
			
		||||
 */
 | 
			
		||||
public interface IWiredNode extends IPacketNetwork
 | 
			
		||||
{
 | 
			
		||||
@@ -34,6 +34,17 @@ public interface IWiredNode extends IPacketNetwork
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    IWiredElement getElement();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The network this node is currently connected to. Note that this may change
 | 
			
		||||
     * after any network operation, so it should not be cached.
 | 
			
		||||
     *
 | 
			
		||||
     * This should only be used on the server thread.
 | 
			
		||||
     *
 | 
			
		||||
     * @return This node's network.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    IWiredNetwork getNetwork();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a connection from this node to another.
 | 
			
		||||
     *
 | 
			
		||||
@@ -46,19 +57,9 @@ public interface IWiredNode extends IPacketNetwork
 | 
			
		||||
     */
 | 
			
		||||
    default boolean connectTo( @Nonnull IWiredNode node )
 | 
			
		||||
    {
 | 
			
		||||
        return this.getNetwork().connect( this, node );
 | 
			
		||||
        return getNetwork().connect( this, node );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The network this node is currently connected to. Note that this may change after any network operation, so it should not be cached.
 | 
			
		||||
     *
 | 
			
		||||
     * This should only be used on the server thread.
 | 
			
		||||
     *
 | 
			
		||||
     * @return This node's network.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    IWiredNetwork getNetwork();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Destroy a connection between this node and another.
 | 
			
		||||
     *
 | 
			
		||||
@@ -72,33 +73,36 @@ public interface IWiredNode extends IPacketNetwork
 | 
			
		||||
     */
 | 
			
		||||
    default boolean disconnectFrom( @Nonnull IWiredNode node )
 | 
			
		||||
    {
 | 
			
		||||
        return this.getNetwork().disconnect( this, node );
 | 
			
		||||
        return getNetwork().disconnect( this, node );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sever all connections this node has, removing it from this network.
 | 
			
		||||
     *
 | 
			
		||||
     * This should only be used on the server thread. You should only call this on nodes that your network element owns.
 | 
			
		||||
     * This should only be used on the server thread. You should only call this on nodes
 | 
			
		||||
     * that your network element owns.
 | 
			
		||||
     *
 | 
			
		||||
     * @return Whether this node was removed from the network. One cannot remove a node from a network where it is the only element.
 | 
			
		||||
     * @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 IWiredNetwork#remove(IWiredNode)
 | 
			
		||||
     */
 | 
			
		||||
    default boolean remove()
 | 
			
		||||
    {
 | 
			
		||||
        return this.getNetwork().remove( this );
 | 
			
		||||
        return getNetwork().remove( this );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Mark this node's peripherals as having changed.
 | 
			
		||||
     *
 | 
			
		||||
     * This should only be used on the server thread. You should only call this on nodes that your network element owns.
 | 
			
		||||
     * This should only be used on the server thread. You should only call this on nodes
 | 
			
		||||
     * that your network element owns.
 | 
			
		||||
     *
 | 
			
		||||
     * @param peripherals The new peripherals for this node.
 | 
			
		||||
     * @see IWiredNetwork#updatePeripherals(IWiredNode, Map)
 | 
			
		||||
     */
 | 
			
		||||
    default void updatePeripherals( @Nonnull Map<String, IPeripheral> peripherals )
 | 
			
		||||
    {
 | 
			
		||||
        this.getNetwork().updatePeripherals( this, peripherals );
 | 
			
		||||
        getNetwork().updatePeripherals( this, peripherals );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.network.wired;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.network.IPacketSender;
 | 
			
		||||
@@ -13,14 +12,16 @@ import javax.annotation.Nonnull;
 | 
			
		||||
/**
 | 
			
		||||
 * An object on a {@link IWiredNetwork} capable of sending packets.
 | 
			
		||||
 *
 | 
			
		||||
 * Unlike a regular {@link IPacketSender}, this must be associated with the node you are attempting to to send the packet from.
 | 
			
		||||
 * Unlike a regular {@link IPacketSender}, this must be associated with the node you are attempting to
 | 
			
		||||
 * to send the packet from.
 | 
			
		||||
 */
 | 
			
		||||
public interface IWiredSender extends IPacketSender
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * The node in the network representing this object.
 | 
			
		||||
     *
 | 
			
		||||
     * This should be used as a proxy for the main network. One should send packets and register receivers through this object.
 | 
			
		||||
     * This should be used as a proxy for the main network. One should send packets
 | 
			
		||||
     * and register receivers through this object.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The node for this element.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,45 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
package dan200.computercraft.api.peripheral;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.lua.GenericSource;
 | 
			
		||||
import net.minecraft.world.Container;
 | 
			
		||||
import net.minecraft.world.level.block.entity.BlockEntity;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A {@link GenericSource} which provides methods for a peripheral.
 | 
			
		||||
 *
 | 
			
		||||
 * Unlike a {@link GenericSource}, all methods <strong>should</strong> target the same type, for instance a
 | 
			
		||||
 * {@link BlockEntity} subclass or a capability interface. This is not currently enforced.
 | 
			
		||||
 */
 | 
			
		||||
public interface GenericPeripheral extends GenericSource
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the type of the exposed peripheral.
 | 
			
		||||
     *
 | 
			
		||||
     * Unlike normal {@link IPeripheral}s, {@link GenericPeripheral} do not have to have a type. By default, the
 | 
			
		||||
     * resulting peripheral uses the resource name of the wrapped {@link BlockEntity} (for instance {@literal minecraft:chest}).
 | 
			
		||||
     *
 | 
			
		||||
     * However, in some cases it may be more appropriate to specify a more readable name. Overriding this method allows
 | 
			
		||||
     * you to do so.
 | 
			
		||||
     *
 | 
			
		||||
     * When multiple {@link GenericPeripheral}s return a non-empty peripheral type for a single tile entity, the
 | 
			
		||||
     * lexicographically smallest will be chosen. In order to avoid this conflict, this method should only be
 | 
			
		||||
     * implemented when your peripheral targets a single tile entity <strong>AND</strong> it's likely that you're the
 | 
			
		||||
     * only mod to do so. Similarly this should <strong>NOT</strong> be implemented when your methods target an
 | 
			
		||||
     * interface (i.e. {@link Container}).
 | 
			
		||||
     *
 | 
			
		||||
     * @return The type of this peripheral or {@link PeripheralType#untyped()}.
 | 
			
		||||
     * @see IPeripheral#getType()
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    default PeripheralType getType()
 | 
			
		||||
    {
 | 
			
		||||
        return PeripheralType.untyped();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.peripheral;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI;
 | 
			
		||||
@@ -13,15 +12,16 @@ import dan200.computercraft.api.lua.ILuaCallback;
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaContext;
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaTask;
 | 
			
		||||
import dan200.computercraft.api.lua.MethodResult;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
import net.minecraft.world.level.Level;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The interface passed to peripherals by computers or turtles, providing methods that they can call. This should not be implemented by your classes. Do not
 | 
			
		||||
 * interact with computers except via this interface.
 | 
			
		||||
 * The interface passed to peripherals by computers or turtles, providing methods
 | 
			
		||||
 * that they can call. This should not be implemented by your classes. Do not interact
 | 
			
		||||
 * with computers except via this interface.
 | 
			
		||||
 */
 | 
			
		||||
public interface IComputerAccess
 | 
			
		||||
{
 | 
			
		||||
@@ -30,10 +30,10 @@ public interface IComputerAccess
 | 
			
		||||
     *
 | 
			
		||||
     * @param desiredLocation The location on the computer's file system where you would like the mount to be mounted.
 | 
			
		||||
     * @param mount           The mount object to mount on the computer.
 | 
			
		||||
     * @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a file in the desired location.
 | 
			
		||||
     * Store this value if you wish to unmount the mount later.
 | 
			
		||||
     * @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
 | 
			
		||||
     * file in the desired location. Store this value if you wish to unmount the mount later.
 | 
			
		||||
     * @throws NotAttachedException If the peripheral has been detached.
 | 
			
		||||
     * @see ComputerCraftAPI#createSaveDirMount(World, String, long)
 | 
			
		||||
     * @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
 | 
			
		||||
     * @see ComputerCraftAPI#createResourceMount(String, String)
 | 
			
		||||
     * @see #mount(String, IMount, String)
 | 
			
		||||
     * @see #mountWritable(String, IWritableMount)
 | 
			
		||||
@@ -43,7 +43,7 @@ public interface IComputerAccess
 | 
			
		||||
    @Nullable
 | 
			
		||||
    default String mount( @Nonnull String desiredLocation, @Nonnull IMount mount )
 | 
			
		||||
    {
 | 
			
		||||
        return this.mount( desiredLocation, mount, this.getAttachmentName() );
 | 
			
		||||
        return mount( desiredLocation, mount, getAttachmentName() );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -52,10 +52,10 @@ public interface IComputerAccess
 | 
			
		||||
     * @param desiredLocation The location on the computer's file system where you would like the mount to be mounted.
 | 
			
		||||
     * @param mount           The mount object to mount on the computer.
 | 
			
		||||
     * @param driveName       A custom name to give for this mount location, as returned by {@code fs.getDrive()}.
 | 
			
		||||
     * @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a file in the desired location.
 | 
			
		||||
     * Store this value if you wish to unmount the mount later.
 | 
			
		||||
     * @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
 | 
			
		||||
     * file in the desired location. Store this value if you wish to unmount the mount later.
 | 
			
		||||
     * @throws NotAttachedException If the peripheral has been detached.
 | 
			
		||||
     * @see ComputerCraftAPI#createSaveDirMount(World, String, long)
 | 
			
		||||
     * @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
 | 
			
		||||
     * @see ComputerCraftAPI#createResourceMount(String, String)
 | 
			
		||||
     * @see #mount(String, IMount)
 | 
			
		||||
     * @see #mountWritable(String, IWritableMount)
 | 
			
		||||
@@ -65,26 +65,15 @@ public interface IComputerAccess
 | 
			
		||||
    @Nullable
 | 
			
		||||
    String mount( @Nonnull String desiredLocation, @Nonnull IMount mount, @Nonnull String driveName );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a string, unique to the computer, by which the computer refers to this peripheral. For directly attached peripherals this will be
 | 
			
		||||
     * "left","right","front","back",etc, but for peripherals attached remotely it will be different. It is good practice to supply this string when raising
 | 
			
		||||
     * events to the computer, so that the computer knows from which peripheral the event came.
 | 
			
		||||
     *
 | 
			
		||||
     * @return A string unique to the computer, but not globally.
 | 
			
		||||
     * @throws NotAttachedException If the peripheral has been detached.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    String getAttachmentName();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Mount a mount onto the computer's file system in a writable mode.
 | 
			
		||||
     *
 | 
			
		||||
     * @param desiredLocation The location on the computer's file system where you would like the mount to be mounted.
 | 
			
		||||
     * @param mount           The mount object to mount on the computer.
 | 
			
		||||
     * @return The location on the computer's file system where you the mount mounted, or null if there was already a file in the desired location. Store
 | 
			
		||||
     * this value if you wish to unmount the mount later.
 | 
			
		||||
     * @return The location on the computer's file system where you the mount mounted, or null if there was already a
 | 
			
		||||
     * file in the desired location. Store this value if you wish to unmount the mount later.
 | 
			
		||||
     * @throws NotAttachedException If the peripheral has been detached.
 | 
			
		||||
     * @see ComputerCraftAPI#createSaveDirMount(World, String, long)
 | 
			
		||||
     * @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
 | 
			
		||||
     * @see ComputerCraftAPI#createResourceMount(String, String)
 | 
			
		||||
     * @see #mount(String, IMount)
 | 
			
		||||
     * @see #unmount(String)
 | 
			
		||||
@@ -93,7 +82,7 @@ public interface IComputerAccess
 | 
			
		||||
    @Nullable
 | 
			
		||||
    default String mountWritable( @Nonnull String desiredLocation, @Nonnull IWritableMount mount )
 | 
			
		||||
    {
 | 
			
		||||
        return this.mountWritable( desiredLocation, mount, this.getAttachmentName() );
 | 
			
		||||
        return mountWritable( desiredLocation, mount, getAttachmentName() );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -102,10 +91,10 @@ public interface IComputerAccess
 | 
			
		||||
     * @param desiredLocation The location on the computer's file system where you would like the mount to be mounted.
 | 
			
		||||
     * @param mount           The mount object to mount on the computer.
 | 
			
		||||
     * @param driveName       A custom name to give for this mount location, as returned by {@code fs.getDrive()}.
 | 
			
		||||
     * @return The location on the computer's file system where you the mount mounted, or null if there was already a file in the desired location. Store
 | 
			
		||||
     * this value if you wish to unmount the mount later.
 | 
			
		||||
     * @return The location on the computer's file system where you the mount mounted, or null if there was already a
 | 
			
		||||
     * file in the desired location. Store this value if you wish to unmount the mount later.
 | 
			
		||||
     * @throws NotAttachedException If the peripheral has been detached.
 | 
			
		||||
     * @see ComputerCraftAPI#createSaveDirMount(World, String, long)
 | 
			
		||||
     * @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
 | 
			
		||||
     * @see ComputerCraftAPI#createResourceMount(String, String)
 | 
			
		||||
     * @see #mount(String, IMount)
 | 
			
		||||
     * @see #unmount(String)
 | 
			
		||||
@@ -114,16 +103,18 @@ public interface IComputerAccess
 | 
			
		||||
    String mountWritable( @Nonnull String desiredLocation, @Nonnull IWritableMount mount, @Nonnull String driveName );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Unmounts a directory previously mounted onto the computers file system by {@link #mount(String, IMount)} or {@link #mountWritable(String,
 | 
			
		||||
     * IWritableMount)}.
 | 
			
		||||
     * Unmounts a directory previously mounted onto the computers file system by {@link #mount(String, IMount)}
 | 
			
		||||
     * or {@link #mountWritable(String, IWritableMount)}.
 | 
			
		||||
     *
 | 
			
		||||
     * When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be able to access it. All directories
 | 
			
		||||
     * mounted by a mount or mountWritable are automatically unmounted when the peripheral is attached if they have not been explicitly unmounted.
 | 
			
		||||
     * When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be
 | 
			
		||||
     * able to access it. All directories mounted by a mount or mountWritable are automatically unmounted when the
 | 
			
		||||
     * peripheral is attached if they have not been explicitly unmounted.
 | 
			
		||||
     *
 | 
			
		||||
     * Note that you cannot unmount another peripheral's mounts.
 | 
			
		||||
     *
 | 
			
		||||
     * @param location The desired location in the computers file system of the directory to unmount. This must be the location of a directory
 | 
			
		||||
     *                 previously mounted by {@link #mount(String, IMount)} or {@link #mountWritable(String, IWritableMount)}, as indicated by their return value.
 | 
			
		||||
     * @param location The desired location in the computers file system of the directory to unmount.
 | 
			
		||||
     *                 This must be the location of a directory previously mounted by {@link #mount(String, IMount)} or
 | 
			
		||||
     *                 {@link #mountWritable(String, IWritableMount)}, as indicated by their return value.
 | 
			
		||||
     * @throws NotAttachedException  If the peripheral has been detached.
 | 
			
		||||
     * @throws IllegalStateException If the mount does not exist, or was mounted by another peripheral.
 | 
			
		||||
     * @see #mount(String, IMount)
 | 
			
		||||
@@ -134,22 +125,26 @@ public interface IComputerAccess
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the numerical ID of this computer.
 | 
			
		||||
     *
 | 
			
		||||
     * This is the same number obtained by calling {@code os.getComputerID()} or running the "id" program from lua, and is guaranteed unique. This number
 | 
			
		||||
     * will be positive.
 | 
			
		||||
     * This is the same number obtained by calling {@code os.getComputerID()} or running the "id" program from lua,
 | 
			
		||||
     * and is guaranteed unique. This number will be positive.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The identifier.
 | 
			
		||||
     */
 | 
			
		||||
    int getID();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Causes an event to be raised on this computer, which the computer can respond to by calling {@code os.pullEvent()}. This can be used to notify the
 | 
			
		||||
     * computer when things happen in the world or to this peripheral.
 | 
			
		||||
     * Causes an event to be raised on this computer, which the computer can respond to by calling
 | 
			
		||||
     * {@code os.pullEvent()}. This can be used to notify the computer when things happen in the world or to
 | 
			
		||||
     * this peripheral.
 | 
			
		||||
     *
 | 
			
		||||
     * @param event     A string identifying the type of event that has occurred, this will be returned as the first value from {@code os.pullEvent()}. It
 | 
			
		||||
     *                  is recommended that you you choose a name that is unique, and recognisable as originating from your peripheral. eg: If your peripheral type is
 | 
			
		||||
     *                  "button", a suitable event would be "button_pressed".
 | 
			
		||||
     * @param arguments In addition to a name, you may pass an array of extra arguments to the event, that will be supplied as extra return values to
 | 
			
		||||
     *                  os.pullEvent(). Objects in the array will be converted to lua data types in the same fashion as the return values of IPeripheral.callMethod().
 | 
			
		||||
     * @param event     A string identifying the type of event that has occurred, this will be
 | 
			
		||||
     *                  returned as the first value from {@code os.pullEvent()}. It is recommended that you
 | 
			
		||||
     *                  you choose a name that is unique, and recognisable as originating from your
 | 
			
		||||
     *                  peripheral. eg: If your peripheral type is "button", a suitable event would be
 | 
			
		||||
     *                  "button_pressed".
 | 
			
		||||
     * @param arguments In addition to a name, you may pass an array of extra arguments to the event, that will
 | 
			
		||||
     *                  be supplied as extra return values to os.pullEvent(). Objects in the array will be converted
 | 
			
		||||
     *                  to lua data types in the same fashion as the return values of IPeripheral.callMethod().
 | 
			
		||||
     *
 | 
			
		||||
     *                  You may supply {@code null} to indicate that no arguments are to be supplied.
 | 
			
		||||
     * @throws NotAttachedException If the peripheral has been detached.
 | 
			
		||||
@@ -157,6 +152,19 @@ public interface IComputerAccess
 | 
			
		||||
     */
 | 
			
		||||
    void queueEvent( @Nonnull String event, @Nullable Object... arguments );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a string, unique to the computer, by which the computer refers to this peripheral.
 | 
			
		||||
     * For directly attached peripherals this will be "left","right","front","back",etc, but
 | 
			
		||||
     * for peripherals attached remotely it will be different. It is good practice to supply
 | 
			
		||||
     * this string when raising events to the computer, so that the computer knows from
 | 
			
		||||
     * which peripheral the event came.
 | 
			
		||||
     *
 | 
			
		||||
     * @return A string unique to the computer, but not globally.
 | 
			
		||||
     * @throws NotAttachedException If the peripheral has been detached.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    String getAttachmentName();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a set of peripherals that this computer access can "see", along with their attachment name.
 | 
			
		||||
     *
 | 
			
		||||
@@ -171,8 +179,8 @@ public interface IComputerAccess
 | 
			
		||||
    Map<String, IPeripheral> getAvailablePeripherals();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a reachable peripheral with the given attachment name. This is a equivalent to {@link #getAvailablePeripherals()}{@code .get(name)}, though may
 | 
			
		||||
     * be more efficient.
 | 
			
		||||
     * Get a reachable peripheral with the given attachment name. This is a equivalent to
 | 
			
		||||
     * {@link #getAvailablePeripherals()}{@code .get(name)}, though may be more efficient.
 | 
			
		||||
     *
 | 
			
		||||
     * @param name The peripheral's attached name
 | 
			
		||||
     * @return The reachable peripheral, or {@code null} if none can be found.
 | 
			
		||||
@@ -184,11 +192,13 @@ public interface IComputerAccess
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a {@link IWorkMonitor} for tasks your peripheral might execute on the main (server) thread.
 | 
			
		||||
     *
 | 
			
		||||
     * This should be used to ensure your peripheral integrates with ComputerCraft's monitoring and limiting of how much server time each computer consumes.
 | 
			
		||||
     * You should not need to use this if you use {@link ILuaContext#issueMainThreadTask(ILuaTask)} - this is intended for mods with their own system for
 | 
			
		||||
     * running work on the main thread.
 | 
			
		||||
     * This should be used to ensure your peripheral integrates with ComputerCraft's monitoring and limiting of how much
 | 
			
		||||
     * server time each computer consumes. You should not need to use this if you use
 | 
			
		||||
     * {@link ILuaContext#issueMainThreadTask(ILuaTask)} - this is intended for mods with their own system for running
 | 
			
		||||
     * work on the main thread.
 | 
			
		||||
     *
 | 
			
		||||
     * Please note that the returned implementation is <em>not</em> thread-safe, and should only be used from the main thread.
 | 
			
		||||
     * Please note that the returned implementation is <em>not</em> thread-safe, and should only be used from the main
 | 
			
		||||
     * thread.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The work monitor for the main thread, or {@code null} if this computer does not have one.
 | 
			
		||||
     * @throws NotAttachedException If the peripheral has been detached.
 | 
			
		||||
 
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user