mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-11-04 07:32:59 +00:00 
			
		
		
		
	Compare commits
	
		
			295 Commits
		
	
	
		
			v1.12.2-1.
			...
			v1.14.4-1.
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					bf6d017ad1 | ||
| 
						 | 
					8b1773dd60 | ||
| 
						 | 
					a706300598 | ||
| 
						 | 
					2541c3c5e6 | ||
| 
						 | 
					41a1b99f7d | ||
| 
						 | 
					1862a439e2 | ||
| 
						 | 
					018ecfbaa0 | ||
| 
						 | 
					4c8fd4fc35 | ||
| 
						 | 
					35c1b10224 | ||
| 
						 | 
					c1c01bef7c | ||
| 
						 | 
					a48c3d0ba8 | ||
| 
						 | 
					93a9ebc4f6 | ||
| 
						 | 
					7cc2bd43c6 | ||
| 
						 | 
					393e628721 | ||
| 
						 | 
					0bcd28e58c | ||
| 
						 | 
					42f5389fb8 | ||
| 
						 | 
					041cfe91b4 | ||
| 
						 | 
					0f82a4589b | ||
| 
						 | 
					4320a4f851 | ||
| 
						 | 
					037cbabb32 | ||
| 
						 | 
					0dde859582 | ||
| 
						 | 
					e59c043fb6 | ||
| 
						 | 
					ae928c4397 | ||
| 
						 | 
					da41c65128 | ||
| 
						 | 
					4d18234714 | ||
| 
						 | 
					d254c6464b | ||
| 
						 | 
					3a5d50e572 | ||
| 
						 | 
					03b6d2f1ab | ||
| 
						 | 
					b0397ed3c5 | ||
| 
						 | 
					fa70ebcac2 | ||
| 
						 | 
					86e0330100 | ||
| 
						 | 
					92567b4d7e | ||
| 
						 | 
					0ae70fed13 | ||
| 
						 | 
					3b7300543a | ||
| 
						 | 
					642351af1a | ||
| 
						 | 
					121802a683 | ||
| 
						 | 
					08cf55e55f | ||
| 
						 | 
					3c8c0d78ef | ||
| 
						 | 
					c4d18aa9ca | ||
| 
						 | 
					2d4a87adc9 | ||
| 
						 | 
					bedac71e3d | ||
| 
						 | 
					ee4e42e730 | ||
| 
						 | 
					0de75f05dd | ||
| 
						 | 
					be6dd21e54 | ||
| 
						 | 
					927ddb0bde | ||
| 
						 | 
					a8fadabaf1 | ||
| 
						 | 
					44d0f78c1b | ||
| 
						 | 
					38f9a015ca | ||
| 
						 | 
					c311cdc6f5 | ||
| 
						 | 
					a93e0f3284 | ||
| 
						 | 
					14b3065ba4 | ||
| 
						 | 
					3ea2d6a0a8 | ||
| 
						 | 
					c802290437 | ||
| 
						 | 
					f7781defe5 | ||
| 
						 | 
					418420523a | ||
| 
						 | 
					d342a1f368 | ||
| 
						 | 
					81f85361d5 | ||
| 
						 | 
					f1621b30ec | ||
| 
						 | 
					d4f6a594b6 | ||
| 
						 | 
					ff5ba5c131 | ||
| 
						 | 
					4243f30308 | ||
| 
						 | 
					813e91073d | ||
| 
						 | 
					7250f22ff6 | ||
| 
						 | 
					db31a53bba | ||
| 
						 | 
					3023f235a4 | ||
| 
						 | 
					79cd8b4da5 | ||
| 
						 | 
					8e4d311cd9 | ||
| 
						 | 
					9bd8c86a94 | ||
| 
						 | 
					cbc0c1d0b6 | ||
| 
						 | 
					49c37857d4 | ||
| 
						 | 
					b1139a4bf6 | ||
| 
						 | 
					7e8559278e | ||
| 
						 | 
					1e7f1c98fc | ||
| 
						 | 
					a802f25dd6 | ||
| 
						 | 
					f1d6d21d6d | ||
| 
						 | 
					a80302c513 | ||
| 
						 | 
					1c46949da7 | ||
| 
						 | 
					07a56454a0 | ||
| 
						 | 
					a0e72d02c8 | ||
| 
						 | 
					455a59ca85 | ||
| 
						 | 
					46d78af068 | ||
| 
						 | 
					08d22fd3df | ||
| 
						 | 
					e6c691a8f8 | ||
| 
						 | 
					4b0e5c445c | ||
| 
						 | 
					eb5cff1045 | ||
| 
						 | 
					35c7792aa2 | ||
| 
						 | 
					521688d630 | ||
| 
						 | 
					75e2845c01 | ||
| 
						 | 
					2f96283286 | ||
| 
						 | 
					cbe6e9b5f5 | ||
| 
						 | 
					2ab79cf474 | ||
| 
						 | 
					6ce34aba79 | ||
| 
						 | 
					5eeb320b60 | ||
| 
						 | 
					93310850d2 | ||
| 
						 | 
					a2880b12ca | ||
| 
						 | 
					cef2657048 | ||
| 
						 | 
					ccd85eb055 | ||
| 
						 | 
					303b57779a | ||
| 
						 | 
					6279816ecc | ||
| 
						 | 
					4ae77261fa | ||
| 
						 | 
					4b7d843b78 | ||
| 
						 | 
					1c28df65c3 | ||
| 
						 | 
					85b740f484 | ||
| 
						 | 
					f9929cb27d | ||
| 
						 | 
					bafab1ac07 | ||
| 
						 | 
					e05c262468 | ||
| 
						 | 
					acfb72246c | ||
| 
						 | 
					9d51c4c340 | ||
| 
						 | 
					18068effec | ||
| 
						 | 
					7a3f7d3bba | ||
| 
						 | 
					95aa48c456 | ||
| 
						 | 
					6ea8ca991b | ||
| 
						 | 
					f1e551b960 | ||
| 
						 | 
					772c54ec74 | ||
| 
						 | 
					13cb789c18 | ||
| 
						 | 
					42220c4268 | ||
| 
						 | 
					3052506e2e | ||
| 
						 | 
					0741daa7eb | ||
| 
						 | 
					b4aa554279 | ||
| 
						 | 
					8fe2abe0ae | ||
| 
						 | 
					5af789ae11 | ||
| 
						 | 
					904a168d5c | ||
| 
						 | 
					724441eddc | ||
| 
						 | 
					f68ab3edd1 | ||
| 
						 | 
					68542aca3a | ||
| 
						 | 
					594bc4203c | ||
| 
						 | 
					57318b022d | ||
| 
						 | 
					761159aa93 | ||
| 
						 | 
					29dce26bf6 | ||
| 
						 | 
					717ab69093 | ||
| 
						 | 
					138a2cf08f | ||
| 
						 | 
					81daf82647 | ||
| 
						 | 
					f3798bfb63 | ||
| 
						 | 
					bc07dfad2e | ||
| 
						 | 
					8dd1c2a6cc | ||
| 
						 | 
					d10b657a54 | ||
| 
						 | 
					f90da739eb | ||
| 
						 | 
					d9cadf64e8 | ||
| 
						 | 
					15d4a55cd8 | ||
| 
						 | 
					309cbdb8be | ||
| 
						 | 
					39a9ad0ce7 | ||
| 
						 | 
					0f3c44c926 | ||
| 
						 | 
					a0e7c4a74c | ||
| 
						 | 
					7d428030df | ||
| 
						 | 
					00c395f689 | ||
| 
						 | 
					d8e1c73d26 | ||
| 
						 | 
					ffa4cc241b | ||
| 
						 | 
					6f1b740c8f | ||
| 
						 | 
					3406ba3ebf | ||
| 
						 | 
					b6715bd812 | ||
| 
						 | 
					18aee02221 | ||
| 
						 | 
					401bbf2e6a | ||
| 
						 | 
					7467b7f88a | ||
| 
						 | 
					c82d8a7c2a | ||
| 
						 | 
					6b81bcf334 | ||
| 
						 | 
					3d67421d98 | ||
| 
						 | 
					acac70675d | ||
| 
						 | 
					56434259c1 | ||
| 
						 | 
					da7e4b9016 | ||
| 
						 | 
					d4b8650d21 | ||
| 
						 | 
					17645a79f0 | ||
| 
						 | 
					ce1f14a010 | ||
| 
						 | 
					43050426de | ||
| 
						 | 
					b05f60c98b | ||
| 
						 | 
					c44c560f96 | ||
| 
						 | 
					e839ef54af | ||
| 
						 | 
					0cb659d78c | ||
| 
						 | 
					9048deeb95 | ||
| 
						 | 
					5592ebae7d | ||
| 
						 | 
					b076c32fd1 | ||
| 
						 | 
					a48f1e310f | ||
| 
						 | 
					19aca001d7 | ||
| 
						 | 
					114f913bf8 | ||
| 
						 | 
					1c9810890a | ||
| 
						 | 
					b11beb508b | ||
| 
						 | 
					af8d4da594 | ||
| 
						 | 
					a81db2cda6 | ||
| 
						 | 
					99bdff0f92 | ||
| 
						 | 
					bb138326df | ||
| 
						 | 
					5b0ce7410d | ||
| 
						 | 
					d5ea22d1a0 | ||
| 
						 | 
					210f3fa9e2 | ||
| 
						 | 
					d661cfa88b | ||
| 
						 | 
					68bf3a71dc | ||
| 
						 | 
					3cdb12d293 | ||
| 
						 | 
					ad33acd7d1 | ||
| 
						 | 
					0ec3884e98 | ||
| 
						 | 
					7f2471d6b2 | ||
| 
						 | 
					e0660b1dab | ||
| 
						 | 
					2182cfbeb7 | ||
| 
						 | 
					8fafec4915 | ||
| 
						 | 
					b9fd690ecb | ||
| 
						 | 
					2f2ada4416 | ||
| 
						 | 
					9c951c58d9 | ||
| 
						 | 
					4b4b47e231 | ||
| 
						 | 
					2c027adb68 | ||
| 
						 | 
					4a25e7a178 | ||
| 
						 | 
					55d54fec63 | ||
| 
						 | 
					220e4bd660 | ||
| 
						 | 
					978c28a686 | ||
| 
						 | 
					b867ada5e5 | ||
| 
						 | 
					7071cc972b | ||
| 
						 | 
					6898f932a0 | ||
| 
						 | 
					2e0ef6385d | ||
| 
						 | 
					f93da7ea51 | ||
| 
						 | 
					1210bb8a4d | ||
| 
						 | 
					48a71e96eb | ||
| 
						 | 
					3bf47b5290 | ||
| 
						 | 
					9e9f199e55 | ||
| 
						 | 
					5a8a111857 | ||
| 
						 | 
					48ba247ab4 | ||
| 
						 | 
					362dbd97ac | ||
| 
						 | 
					aa0e1883d1 | ||
| 
						 | 
					9cdbcb4332 | ||
| 
						 | 
					23ddd4feb5 | ||
| 
						 | 
					fcaa777c95 | ||
| 
						 | 
					b195cab6a7 | ||
| 
						 | 
					63dc0daa09 | ||
| 
						 | 
					34602ec4be | ||
| 
						 | 
					f3ce44042f | ||
| 
						 | 
					4205f18f0c | ||
| 
						 | 
					6be330ae8d | ||
| 
						 | 
					4569af2130 | ||
| 
						 | 
					765c31315a | ||
| 
						 | 
					0e191e42a0 | ||
| 
						 | 
					ca34b2a1b8 | ||
| 
						 | 
					7afc3e5260 | ||
| 
						 | 
					f9e13ca67a | ||
| 
						 | 
					810258e9b8 | ||
| 
						 | 
					5e462adc5c | ||
| 
						 | 
					1fd0b40776 | ||
| 
						 | 
					2965fb666f | ||
| 
						 | 
					390575ab4d | ||
| 
						 | 
					e4ef92ca2d | ||
| 
						 | 
					9bf586b018 | ||
| 
						 | 
					173ea72001 | ||
| 
						 | 
					1230cabcb0 | ||
| 
						 | 
					6ed03e1fcd | ||
| 
						 | 
					c4b371b124 | ||
| 
						 | 
					a600213b00 | ||
| 
						 | 
					7799b8d4cb | ||
| 
						 | 
					245bf26480 | ||
| 
						 | 
					5d05205d69 | ||
| 
						 | 
					853e2622a1 | ||
| 
						 | 
					d0bf9e9cd7 | ||
| 
						 | 
					7a7951ae68 | ||
| 
						 | 
					bd28955c8e | ||
| 
						 | 
					e46f09a939 | ||
| 
						 | 
					71b1f8138d | ||
| 
						 | 
					1d82a1c98c | ||
| 
						 | 
					b5f60f3f11 | ||
| 
						 | 
					259665d9f1 | ||
| 
						 | 
					ba823bae13 | ||
| 
						 | 
					1290a4402c | ||
| 
						 | 
					379076a5e2 | ||
| 
						 | 
					d12bdf50d8 | ||
| 
						 | 
					cbfd5aeeee | ||
| 
						 | 
					41429bdc0b | ||
| 
						 | 
					54b9966feb | ||
| 
						 | 
					105c66127c | ||
| 
						 | 
					765ad0bd3f | ||
| 
						 | 
					dd05478483 | ||
| 
						 | 
					5d028dea39 | ||
| 
						 | 
					629c51d260 | ||
| 
						 | 
					9ea57961af | ||
| 
						 | 
					07b9b1c9c7 | ||
| 
						 | 
					5b942ff9c1 | ||
| 
						 | 
					7b5a918941 | ||
| 
						 | 
					47721bf76b | ||
| 
						 | 
					35ce0974cd | ||
| 
						 | 
					52e1906d42 | ||
| 
						 | 
					eaf24a3ceb | ||
| 
						 | 
					62760e371e | ||
| 
						 | 
					e154e11186 | ||
| 
						 | 
					72d079ef61 | ||
| 
						 | 
					0bfb7049b0 | ||
| 
						 | 
					f7cb526793 | ||
| 
						 | 
					e34e833d3d | ||
| 
						 | 
					a125a19728 | ||
| 
						 | 
					b3e6a53868 | ||
| 
						 | 
					218f8e53bb | ||
| 
						 | 
					d02575528b | ||
| 
						 | 
					c78adb2cdc | ||
| 
						 | 
					3e28f79ce9 | ||
| 
						 | 
					67af7a698b | ||
| 
						 | 
					06e76f9b15 | ||
| 
						 | 
					6d383d005c | ||
| 
						 | 
					c373583723 | ||
| 
						 | 
					f1d10809d5 | ||
| 
						 | 
					474f571798 | ||
| 
						 | 
					fb9c125ab8 | ||
| 
						 | 
					162fb37421 | ||
| 
						 | 
					d953f031f0 | ||
| 
						 | 
					7fde89ad95 | ||
| 
						 | 
					bd04a93ffb | 
@@ -11,5 +11,8 @@ insert_final_newline = true
 | 
			
		||||
[*.md]
 | 
			
		||||
trim_trailing_whitespace = false
 | 
			
		||||
 | 
			
		||||
[*.sexp]
 | 
			
		||||
indent_size = 2
 | 
			
		||||
 | 
			
		||||
[*.properties]
 | 
			
		||||
insert_final_newline = false
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								.github/ISSUE_TEMPLATE/bug_report.md
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/ISSUE_TEMPLATE/bug_report.md
									
									
									
									
										vendored
									
									
								
							@@ -1,7 +1,7 @@
 | 
			
		||||
---
 | 
			
		||||
name: Bug report
 | 
			
		||||
about: Report some misbehaviour in the mod
 | 
			
		||||
 | 
			
		||||
labels: bug
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
<!--
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								.github/ISSUE_TEMPLATE/feature_request.md
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/ISSUE_TEMPLATE/feature_request.md
									
									
									
									
										vendored
									
									
								
							@@ -1,7 +1,7 @@
 | 
			
		||||
---
 | 
			
		||||
name: Feature request
 | 
			
		||||
about: Suggest an idea or improvement
 | 
			
		||||
 | 
			
		||||
labels: enhancement
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
<!--
 | 
			
		||||
@@ -11,4 +11,4 @@ about: Suggest an idea or improvement
 | 
			
		||||
 | 
			
		||||
## Useful information to include:
 | 
			
		||||
 - Explanation of how the feature/change should work.
 | 
			
		||||
 - Some rationale/use case for a feature. I'd like to keep CC:T as minimal as possible, so I like have a solid justification for each feature.
 | 
			
		||||
 - Some rationale/use case for a feature. My general approach to designing new features is to ask yourself "what issue are we trying to solve" and _then_ "is this the best way to solve this issue?".
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								.github/pull_request_template.md
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.github/pull_request_template.md
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
## A quick checklist
 | 
			
		||||
 - If there's a existing issue, please link to it. If not, provide fill out the same information you would in a normal issue - reproduction steps for bugs, rationale for use-case.
 | 
			
		||||
 - If you're working on CraftOS, try to write a few test cases so we can ensure everything continues to work in the future. Tests live in `src/test/resources/test-rom/spec` and can be run with `./gradlew check`.
 | 
			
		||||
							
								
								
									
										39
									
								
								.github/workflows/main-ci.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								.github/workflows/main-ci.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
name: Build
 | 
			
		||||
 | 
			
		||||
on: [push, pull_request]
 | 
			
		||||
 | 
			
		||||
jobs:
 | 
			
		||||
  build:
 | 
			
		||||
    name: Build
 | 
			
		||||
    runs-on: ubuntu-latest
 | 
			
		||||
 | 
			
		||||
    steps:
 | 
			
		||||
    - uses: actions/checkout@v1
 | 
			
		||||
 | 
			
		||||
    - name: Set up JDK 1.8
 | 
			
		||||
      uses: actions/setup-java@v1
 | 
			
		||||
      with:
 | 
			
		||||
        java-version: 1.8
 | 
			
		||||
 | 
			
		||||
    - name: Build with Gradle
 | 
			
		||||
      run: ./gradlew build --no-daemon
 | 
			
		||||
 | 
			
		||||
    - name: Upload Jar
 | 
			
		||||
      uses: actions/upload-artifact@v1
 | 
			
		||||
      with:
 | 
			
		||||
        name: CC-Tweaked
 | 
			
		||||
        path: build/libs
 | 
			
		||||
 | 
			
		||||
  lint-lua:
 | 
			
		||||
    name: Lint Lua
 | 
			
		||||
    runs-on: ubuntu-latest
 | 
			
		||||
 | 
			
		||||
    steps:
 | 
			
		||||
    - uses: actions/checkout@v1
 | 
			
		||||
 | 
			
		||||
    - name: Lint Lua code
 | 
			
		||||
      run: |
 | 
			
		||||
        test -d bin || mkdir bin
 | 
			
		||||
        test -f bin/illuaminate || wget -q -Obin/illuaminate https://squiddev.cc/illuaminate/bin/illuaminate
 | 
			
		||||
        chmod +x bin/illuaminate
 | 
			
		||||
        bin/illuaminate lint
 | 
			
		||||
							
								
								
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -15,3 +15,9 @@
 | 
			
		||||
.idea
 | 
			
		||||
.gradle
 | 
			
		||||
*.DS_Store
 | 
			
		||||
 | 
			
		||||
.classpath
 | 
			
		||||
.project
 | 
			
		||||
.settings/
 | 
			
		||||
bin/
 | 
			
		||||
*.launch
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										34
									
								
								.luacheckrc
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								.luacheckrc
									
									
									
									
									
								
							@@ -1,34 +0,0 @@
 | 
			
		||||
std = "max"
 | 
			
		||||
 | 
			
		||||
ignore = {
 | 
			
		||||
    -- Allow access to undefined globals or their fields. In the future we'll
 | 
			
		||||
    -- define all of CC's globals within this file
 | 
			
		||||
    '113', '143',
 | 
			
		||||
 | 
			
		||||
    -- FIXME: Ignore unused arguments and loop variables
 | 
			
		||||
    '212', '213',
 | 
			
		||||
 | 
			
		||||
    -- Disable line is too long for now. It would be possible to clean
 | 
			
		||||
    -- this up in the future.
 | 
			
		||||
    '631',
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
-- Only run the linter on ROM and bios for now, as the treasure disks
 | 
			
		||||
-- are largely unsupported.
 | 
			
		||||
include_files = {
 | 
			
		||||
    'src/main/resources/assets/computercraft/lua/rom',
 | 
			
		||||
    'src/main/resources/assets/computercraft/lua/bios.lua'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
files['src/main/resources/assets/computercraft/lua/bios.lua'] = {
 | 
			
		||||
    -- Allow declaring and mutating globals
 | 
			
		||||
    allow_defined_top = true,
 | 
			
		||||
    ignore = { '112', '121', '122', '131', '142' },
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
files['src/main/resources/assets/computercraft/lua/rom/apis'] = {
 | 
			
		||||
    -- APIs may define globals on the top level. We'll ignore unused globals,
 | 
			
		||||
    -- as obviously they may be used outside that API.
 | 
			
		||||
    allow_defined_top = true,
 | 
			
		||||
    ignore = { '131' },
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										14
									
								
								.travis.yml
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								.travis.yml
									
									
									
									
									
								
							@@ -1,14 +0,0 @@
 | 
			
		||||
language: java
 | 
			
		||||
 | 
			
		||||
script: ./gradlew build --no-daemon
 | 
			
		||||
 | 
			
		||||
before_cache:
 | 
			
		||||
  - rm -f  $HOME/.gradle/caches/modules-2/modules-2.lock
 | 
			
		||||
  - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
 | 
			
		||||
cache:
 | 
			
		||||
  directories:
 | 
			
		||||
    - $HOME/.gradle/caches/
 | 
			
		||||
    - $HOME/.gradle/wrapper/s
 | 
			
		||||
 | 
			
		||||
jdk:
 | 
			
		||||
    - oraclejdk8
 | 
			
		||||
							
								
								
									
										32
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								README.md
									
									
									
									
									
								
							@@ -1,5 +1,5 @@
 | 
			
		||||
# 
 | 
			
		||||
[](https://travis-ci.org/SquidDev-CC/CC-Tweaked)
 | 
			
		||||
[](https://github.com/SquidDev-CC/CC-Tweaked/actions "Current build status") [](https://minecraft.curseforge.com/projects/cc-tweaked "Download CC: Tweaked on CurseForge")
 | 
			
		||||
 | 
			
		||||
CC: Tweaked is a fork of [ComputerCraft](https://github.com/dan200/ComputerCraft), adding programmable computers,
 | 
			
		||||
turtles and more to Minecraft.
 | 
			
		||||
@@ -41,7 +41,35 @@ Any contribution is welcome, be that using the mod, reporting bugs or contributi
 | 
			
		||||
develop CC:T, you'll need to follow these steps:
 | 
			
		||||
 | 
			
		||||
 - **Clone the repository:** `git clone https://github.com/SquidDev-CC/CC-Tweaked.git && cd CC-Tweaked`
 | 
			
		||||
 - **Setup Forge:** `./gradlew setupDecompWorkspace`
 | 
			
		||||
 - **Setup Forge:** `./gradlew build`
 | 
			
		||||
 - **Test your changes:** `./gradlew runClient` (or run the `GradleStart` class from your IDE).
 | 
			
		||||
 | 
			
		||||
If you want to run CC:T in a normal Minecraft instance, run `./gradlew build` and copy the `.jar` from `build/libs`.
 | 
			
		||||
 | 
			
		||||
## Community
 | 
			
		||||
If you need help getting started with CC: Tweaked, want to show off your latest project, or just want to chat about
 | 
			
		||||
ComputerCraft we have a [forum](https://forums.computercraft.cc/) and [Discord guild](https://discord.gg/H2UyJXe)!
 | 
			
		||||
There's also a fairly populated, albeit quiet [IRC channel](http://webchat.esper.net/?channels=#computercraft), if
 | 
			
		||||
that's more your cup of tea.
 | 
			
		||||
 | 
			
		||||
I'd generally recommend you don't contact me directly (email, DM, etc...) unless absolutely necessary (i.e. in order to
 | 
			
		||||
report exploits). You'll get a far quicker response if you ask the whole community!
 | 
			
		||||
 | 
			
		||||
## Using
 | 
			
		||||
If you want to depend on CC: Tweaked, we have a maven repo. However, you should be wary that some functionality is only
 | 
			
		||||
exposed by CC:T's API and not vanilla ComputerCraft. If you wish to support all variations of ComputerCraft, I recommend
 | 
			
		||||
using [cc.crzd.me's maven](https://cc.crzd.me/maven/) instead.
 | 
			
		||||
 | 
			
		||||
```groovy
 | 
			
		||||
dependencies {
 | 
			
		||||
  maven { url 'https://squiddev.cc/maven/' }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
dependencies {
 | 
			
		||||
  implementation "org.squiddev:cc-tweaked-${mc_version}:${cct_version}"
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
You should also be careful to only use classes within the `dan200.computercraft.api` package. Non-API classes are
 | 
			
		||||
subject to change at any point. If you depend on functionality outside the API, file an issue, and we can look into
 | 
			
		||||
exposing more features.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										274
									
								
								build.gradle
									
									
									
									
									
								
							
							
						
						
									
										274
									
								
								build.gradle
									
									
									
									
									
								
							@@ -1,62 +1,90 @@
 | 
			
		||||
 | 
			
		||||
// For those who want the bleeding edge
 | 
			
		||||
buildscript {
 | 
			
		||||
    repositories {
 | 
			
		||||
        jcenter()
 | 
			
		||||
        mavenCentral()
 | 
			
		||||
        maven {
 | 
			
		||||
            name = "forge"
 | 
			
		||||
            url = "http://files.minecraftforge.net/maven"
 | 
			
		||||
            url = "https://files.minecraftforge.net/maven"
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    dependencies {
 | 
			
		||||
        classpath 'com.google.code.gson:gson:2.8.1'
 | 
			
		||||
        classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
 | 
			
		||||
        classpath 'net.sf.proguard:proguard-gradle:6.1.0beta1'
 | 
			
		||||
        classpath 'net.minecraftforge.gradle:ForgeGradle:3.0.154'
 | 
			
		||||
        classpath 'net.sf.proguard:proguard-gradle:6.1.0beta2'
 | 
			
		||||
        classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0'
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
plugins {
 | 
			
		||||
    id 'com.matthewprenger.cursegradle' version '1.0.10'
 | 
			
		||||
    id "checkstyle"
 | 
			
		||||
    id "com.github.hierynomus.license" version "0.15.0"
 | 
			
		||||
    id "com.matthewprenger.cursegradle" version "1.3.0"
 | 
			
		||||
    id "com.github.breadmoirai.github-release" version "2.2.4"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
apply plugin: 'net.minecraftforge.gradle.forge'
 | 
			
		||||
apply plugin: 'net.minecraftforge.gradle'
 | 
			
		||||
apply plugin: 'org.ajoberstar.grgit'
 | 
			
		||||
apply plugin: 'maven-publish'
 | 
			
		||||
apply plugin: 'maven'
 | 
			
		||||
 | 
			
		||||
def mc_version = "1.12.2"
 | 
			
		||||
def main_version = "1.81.1"
 | 
			
		||||
version = "${mc_version}-${main_version}"
 | 
			
		||||
version = mod_version
 | 
			
		||||
 | 
			
		||||
group = "org.squiddev"
 | 
			
		||||
archivesBaseName = "cc-tweaked"
 | 
			
		||||
archivesBaseName = "cc-tweaked-${mc_version}"
 | 
			
		||||
 | 
			
		||||
minecraft {
 | 
			
		||||
    version = "${mc_version}-14.23.4.2749"
 | 
			
		||||
    runDir = "run"
 | 
			
		||||
    replace '${version}', main_version
 | 
			
		||||
    runs {
 | 
			
		||||
        client {
 | 
			
		||||
            workingDirectory project.file('run')
 | 
			
		||||
            property 'forge.logging.markers', 'REGISTRIES'
 | 
			
		||||
            property 'forge.logging.console.level', 'debug'
 | 
			
		||||
 | 
			
		||||
    // the mappings can be changed at any time, and must be in the following format.
 | 
			
		||||
    // snapshot_YYYYMMDD   snapshot are built nightly.
 | 
			
		||||
    // stable_#            stables are built at the discretion of the MCP team.
 | 
			
		||||
    // Use non-default mappings at your own risk. they may not allways work.
 | 
			
		||||
    // simply re-run your setup task after changing the mappings to update your workspace.
 | 
			
		||||
    mappings = "snapshot_20180724"
 | 
			
		||||
    // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
 | 
			
		||||
            mods {
 | 
			
		||||
                computercraft {
 | 
			
		||||
                    source sourceSets.main
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        server {
 | 
			
		||||
            workingDirectory project.file('run')
 | 
			
		||||
            property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
 | 
			
		||||
            property 'forge.logging.console.level', 'debug'
 | 
			
		||||
 | 
			
		||||
            mods {
 | 
			
		||||
                computercraft {
 | 
			
		||||
                    source sourceSets.main
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    mappings channel: 'snapshot', version: "${mappings_version}".toString()
 | 
			
		||||
 | 
			
		||||
    accessTransformer file('src/main/resources/META-INF/accesstransformer.cfg')
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
repositories {
 | 
			
		||||
    maven {
 | 
			
		||||
        name = "JEI"
 | 
			
		||||
        url  = "http://dvs1.progwml6.com/files/maven"
 | 
			
		||||
        name "JEI"
 | 
			
		||||
        url "https://dvs1.progwml6.com/files/maven"
 | 
			
		||||
    }
 | 
			
		||||
    maven {
 | 
			
		||||
        name = "squiddev"
 | 
			
		||||
        url = "https://squiddev.cc/maven"
 | 
			
		||||
        name "SquidDev"
 | 
			
		||||
        url "https://squiddev.cc/maven"
 | 
			
		||||
    }
 | 
			
		||||
    ivy {
 | 
			
		||||
        name "Charset"
 | 
			
		||||
        artifactPattern "https://asie.pl/files/mods/Charset/LibOnly/[module]-[revision](-[classifier]).[ext]"
 | 
			
		||||
    }
 | 
			
		||||
    maven {
 | 
			
		||||
        name "Amadornes"
 | 
			
		||||
        url "https://maven.amadornes.com/"
 | 
			
		||||
    }
 | 
			
		||||
    maven {
 | 
			
		||||
        name "CraftTweaker"
 | 
			
		||||
        url "https://maven.blamejared.com/"
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ivy { artifactPattern "https://asie.pl/files/mods/Charset/LibOnly/[module]-[revision](-[classifier]).[ext]" }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
configurations {
 | 
			
		||||
@@ -66,18 +94,25 @@ configurations {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
dependencies {
 | 
			
		||||
    deobfProvided "mezz.jei:jei_1.12.2:4.8.5.159:api"
 | 
			
		||||
    deobfProvided "pl.asie:Charset-Lib:0.5.4.6"
 | 
			
		||||
    checkstyle "com.puppycrawl.tools:checkstyle:8.25"
 | 
			
		||||
 | 
			
		||||
    runtime "mezz.jei:jei_1.12.2:4.8.5.159"
 | 
			
		||||
    minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
 | 
			
		||||
 | 
			
		||||
    compileOnly fg.deobf("mezz.jei:jei-1.14.4:6.0.0.25:api")
 | 
			
		||||
    compileOnly fg.deobf("com.blamejared.crafttweaker:CraftTweaker-1.14.4:5.0.1.150")
 | 
			
		||||
 | 
			
		||||
    runtimeOnly fg.deobf("mezz.jei:jei-1.14.4:6.0.0.25")
 | 
			
		||||
 | 
			
		||||
    shade 'org.squiddev:Cobalt:0.5.0-SNAPSHOT'
 | 
			
		||||
 | 
			
		||||
    testCompile 'junit:junit:4.11'
 | 
			
		||||
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2'
 | 
			
		||||
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.2'
 | 
			
		||||
 | 
			
		||||
    deployerJars "org.apache.maven.wagon:wagon-ssh:3.0.0"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Compile tasks
 | 
			
		||||
 | 
			
		||||
javadoc {
 | 
			
		||||
    include "dan200/computercraft/api/**/*.java"
 | 
			
		||||
}
 | 
			
		||||
@@ -86,7 +121,13 @@ jar {
 | 
			
		||||
    dependsOn javadoc
 | 
			
		||||
 | 
			
		||||
    manifest {
 | 
			
		||||
        attributes('FMLAT': 'computercraft_at.cfg')
 | 
			
		||||
        attributes(["Specification-Title": "computercraft",
 | 
			
		||||
                    "Specification-Vendor": "SquidDev",
 | 
			
		||||
                    "Specification-Version": "1",
 | 
			
		||||
                    "Implementation-Title": "CC: Tweaked",
 | 
			
		||||
                    "Implementation-Version": "${mod_version}",
 | 
			
		||||
                    "Implementation-Vendor" :"SquidDev",
 | 
			
		||||
                    "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")])
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    from (sourceSets.main.allSource) {
 | 
			
		||||
@@ -96,12 +137,22 @@ jar {
 | 
			
		||||
    from configurations.shade.collect { it.isDirectory() ? it : zipTree(it) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[compileJava, compileTestJava].forEach {
 | 
			
		||||
    it.configure {
 | 
			
		||||
        options.compilerArgs << "-Xlint" << "-Xlint:-processing"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import java.nio.charset.StandardCharsets
 | 
			
		||||
import java.nio.file.*
 | 
			
		||||
import java.util.zip.*
 | 
			
		||||
 | 
			
		||||
import com.google.gson.GsonBuilder
 | 
			
		||||
import com.google.gson.JsonElement
 | 
			
		||||
import com.hierynomus.gradle.license.tasks.LicenseCheck
 | 
			
		||||
import com.hierynomus.gradle.license.tasks.LicenseFormat
 | 
			
		||||
import org.ajoberstar.grgit.Grgit
 | 
			
		||||
import proguard.gradle.ProGuardTask
 | 
			
		||||
 | 
			
		||||
@@ -114,6 +165,7 @@ task proguard(type: ProGuardTask, dependsOn: jar) {
 | 
			
		||||
 | 
			
		||||
    // Add the main runtime jar and all non-shadowed dependencies
 | 
			
		||||
    libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
 | 
			
		||||
    libraryjars "${System.getProperty('java.home')}/lib/jce.jar"
 | 
			
		||||
    doFirst {
 | 
			
		||||
        sourceSets.main.compileClasspath
 | 
			
		||||
            .filter { !it.name.contains("Cobalt") }
 | 
			
		||||
@@ -124,13 +176,14 @@ task proguard(type: ProGuardTask, dependsOn: jar) {
 | 
			
		||||
    dontobfuscate; dontoptimize; keepattributes; keepparameternames
 | 
			
		||||
 | 
			
		||||
    // Proguard will remove directories by default, but that breaks JarMount.
 | 
			
		||||
    keepdirectories 'assets/computercraft/lua**'
 | 
			
		||||
    keepdirectories 'data/computercraft/lua**'
 | 
			
		||||
 | 
			
		||||
    // Preserve ComputerCraft classes - we only want to strip shadowed files.
 | 
			
		||||
    keep 'class dan200.computercraft.** { *; }'
 | 
			
		||||
 | 
			
		||||
    // Preserve the constructors in Cobalt library class, as we init them via reflection
 | 
			
		||||
    keepclassmembers 'class org.squiddev.cobalt.lib.** { <init>(...); }'
 | 
			
		||||
    // LWJGL and Apache bundle Java 9 versions, which is great, but rather breaks Proguard
 | 
			
		||||
    dontwarn 'module-info'
 | 
			
		||||
    dontwarn 'org.apache.**,org.lwjgl.**'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
task proguardMove(dependsOn: proguard) {
 | 
			
		||||
@@ -146,10 +199,10 @@ task proguardMove(dependsOn: proguard) {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
reobfJar.dependsOn proguardMove
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
processResources {
 | 
			
		||||
    inputs.property "version", main_version
 | 
			
		||||
    inputs.property "version", mod_version
 | 
			
		||||
    inputs.property "mcversion", mc_version
 | 
			
		||||
 | 
			
		||||
    def hash = 'none'
 | 
			
		||||
@@ -168,21 +221,21 @@ processResources {
 | 
			
		||||
    inputs.property "commithash", hash
 | 
			
		||||
 | 
			
		||||
    from(sourceSets.main.resources.srcDirs) {
 | 
			
		||||
        include 'mcmod.info'
 | 
			
		||||
        include 'assets/computercraft/lua/rom/help/credits.txt'
 | 
			
		||||
        include 'META-INF/mods.toml'
 | 
			
		||||
        include 'data/computercraft/lua/rom/help/credits.txt'
 | 
			
		||||
 | 
			
		||||
        expand 'version': main_version,
 | 
			
		||||
        expand 'version': mod_version,
 | 
			
		||||
               'mcversion': mc_version,
 | 
			
		||||
               'gitcontributors': contributors.sort(false, String.CASE_INSENSITIVE_ORDER).join('\n')
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    from(sourceSets.main.resources.srcDirs) {
 | 
			
		||||
        exclude 'mcmod.info'
 | 
			
		||||
        exclude 'assets/computercraft/lua/rom/help/credits.txt'
 | 
			
		||||
        exclude 'META-INF/mods.toml'
 | 
			
		||||
        exclude 'data/computercraft/lua/rom/help/credits.txt'
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
task compressJson(dependsOn: extractAnnotationsJar) {
 | 
			
		||||
task compressJson(dependsOn: jar) {
 | 
			
		||||
    group "compact"
 | 
			
		||||
    description "Minifies all JSON files, stripping whitespace"
 | 
			
		||||
 | 
			
		||||
@@ -197,6 +250,7 @@ task compressJson(dependsOn: extractAnnotationsJar) {
 | 
			
		||||
        // Copy over all files in the current jar to the new one, running json files from GSON. As pretty printing
 | 
			
		||||
        // is turned off, they should be minified.
 | 
			
		||||
        new ZipFile(jarPath).withCloseable { inJar ->
 | 
			
		||||
            tempPath.getParentFile().mkdirs()
 | 
			
		||||
            new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(tempPath))).withCloseable { outJar ->
 | 
			
		||||
                inJar.entries().each { entry ->
 | 
			
		||||
                    if(entry.directory) {
 | 
			
		||||
@@ -224,12 +278,106 @@ task compressJson(dependsOn: extractAnnotationsJar) {
 | 
			
		||||
 | 
			
		||||
assemble.dependsOn compressJson
 | 
			
		||||
 | 
			
		||||
// Check tasks
 | 
			
		||||
 | 
			
		||||
test {
 | 
			
		||||
    useJUnitPlatform()
 | 
			
		||||
    testLogging {
 | 
			
		||||
        events "skipped", "failed"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
license {
 | 
			
		||||
    mapping("java", "SLASHSTAR_STYLE")
 | 
			
		||||
    strictCheck true
 | 
			
		||||
 | 
			
		||||
    ext.year = Calendar.getInstance().get(Calendar.YEAR)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[licenseMain, licenseFormatMain].forEach {
 | 
			
		||||
    it.configure {
 | 
			
		||||
        include("**/*.java")
 | 
			
		||||
        exclude("dan200/computercraft/api/**")
 | 
			
		||||
        header rootProject.file('config/license/main.txt')
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[licenseTest, licenseFormatTest].forEach {
 | 
			
		||||
    it.configure {
 | 
			
		||||
        include("**/*.java")
 | 
			
		||||
        header rootProject.file('config/license/main.txt')
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gradle.projectsEvaluated {
 | 
			
		||||
    tasks.withType(LicenseFormat) {
 | 
			
		||||
        outputs.upToDateWhen { false }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
task licenseAPI(type: LicenseCheck);
 | 
			
		||||
task licenseFormatAPI(type: LicenseFormat);
 | 
			
		||||
[licenseAPI, licenseFormatAPI].forEach {
 | 
			
		||||
    it.configure {
 | 
			
		||||
        source = sourceSets.main.java
 | 
			
		||||
        include("dan200/computercraft/api/**")
 | 
			
		||||
        header rootProject.file('config/license/api.txt')
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Upload tasks
 | 
			
		||||
 | 
			
		||||
task checkRelease {
 | 
			
		||||
    group "upload"
 | 
			
		||||
    description "Verifies that everything is ready for a release"
 | 
			
		||||
 | 
			
		||||
    inputs.property "version", mod_version
 | 
			
		||||
    inputs.file("src/main/resources/data/computercraft/lua/rom/help/changelog.txt")
 | 
			
		||||
    inputs.file("src/main/resources/data/computercraft/lua/rom/help/whatsnew.txt")
 | 
			
		||||
 | 
			
		||||
    doLast {
 | 
			
		||||
        def ok = true
 | 
			
		||||
 | 
			
		||||
        // Check we're targetting the current version
 | 
			
		||||
        def whatsnew = new File("src/main/resources/data/computercraft/lua/rom/help/whatsnew.txt").readLines()
 | 
			
		||||
        if (whatsnew[0] != "New features in CC: Tweaked $mod_version") {
 | 
			
		||||
            ok = false
 | 
			
		||||
            project.logger.error("Expected `whatsnew.txt' to target $mod_version.")
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Check "read more" exists and trim it
 | 
			
		||||
        def idx = whatsnew.findIndexOf { it == 'Type "help changelog" to see the full version history.' }
 | 
			
		||||
        if (idx == -1) {
 | 
			
		||||
            ok = false
 | 
			
		||||
            project.logger.error("Must mention the changelog in whatsnew.txt")
 | 
			
		||||
        } else {
 | 
			
		||||
            whatsnew = whatsnew.getAt(0 ..< idx)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Check whatsnew and changelog match.
 | 
			
		||||
        def versionChangelog = "# " + whatsnew.join("\n")
 | 
			
		||||
        def changelog = new File("src/main/resources/data/computercraft/lua/rom/help/changelog.txt").getText()
 | 
			
		||||
        if (!changelog.startsWith(versionChangelog)) {
 | 
			
		||||
            ok = false
 | 
			
		||||
            project.logger.error("whatsnew and changelog are not in sync")
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!ok) throw new IllegalStateException("Could not check release")
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
check.dependsOn checkRelease
 | 
			
		||||
 | 
			
		||||
curseforge {
 | 
			
		||||
    apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : ''
 | 
			
		||||
    project {
 | 
			
		||||
        id = '282001'
 | 
			
		||||
        releaseType = 'release'
 | 
			
		||||
        changelog = "Release notes can be found on the GitHub repository (https://github.com/SquidDev-CC/CC-Tweaked/releases/tag/v${project.version})."
 | 
			
		||||
        changelog = "Release notes can be found on the GitHub repository (https://github.com/SquidDev-CC/CC-Tweaked/releases/tag/v${mc_version}-${mod_version})."
 | 
			
		||||
 | 
			
		||||
        relations {
 | 
			
		||||
            incompatible "computercraft"
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -237,7 +385,7 @@ publishing {
 | 
			
		||||
    publications {
 | 
			
		||||
        mavenJava(MavenPublication) {
 | 
			
		||||
            from components.java
 | 
			
		||||
            artifact sourceJar
 | 
			
		||||
            // artifact sourceJar
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -257,22 +405,22 @@ uploadArchives {
 | 
			
		||||
                pom.project {
 | 
			
		||||
                    name 'CC: Tweaked'
 | 
			
		||||
                    packaging 'jar'
 | 
			
		||||
                    description 'A fork of ComputerCraft which aims to provide earlier access to the more experimental and in-development features of the mod.'
 | 
			
		||||
                    description 'CC: Tweaked is a fork of ComputerCraft, adding programmable computers, turtles and more to Minecraft.'
 | 
			
		||||
                    url 'https://github.com/SquidDev-CC/CC-Tweaked'
 | 
			
		||||
 | 
			
		||||
                    scm {
 | 
			
		||||
                        url 'https://github.com/dan200/ComputerCraft.git'
 | 
			
		||||
                        url 'https://github.com/SquidDev-CC/CC-Tweaked.git'
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    issueManagement {
 | 
			
		||||
                        system 'github'
 | 
			
		||||
                        url 'https://github.com/dan200/ComputerCraft/issues'
 | 
			
		||||
                        url 'https://github.com/SquidDev-CC/CC-Tweaked/issues'
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    licenses {
 | 
			
		||||
                        license {
 | 
			
		||||
                            name 'ComputerCraft Public License, Version 1.0'
 | 
			
		||||
                            url 'https://github.com/dan200/ComputerCraft/blob/master/LICENSE'
 | 
			
		||||
                            url 'https://github.com/SquidDev-CC/CC-Tweaked/blob/master/LICENSE'
 | 
			
		||||
                            distribution 'repo'
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
@@ -286,11 +434,29 @@ uploadArchives {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gradle.projectsEvaluated {
 | 
			
		||||
    tasks.withType(JavaCompile) {
 | 
			
		||||
        options.compilerArgs << "-Xlint"
 | 
			
		||||
githubRelease {
 | 
			
		||||
    token project.hasProperty('githubApiKey') ? project.githubApiKey : ''
 | 
			
		||||
    owner 'SquidDev-CC'
 | 
			
		||||
    repo 'CC-Tweaked'
 | 
			
		||||
    try {
 | 
			
		||||
        targetCommitish = Grgit.open(dir: '.').branch.current().name
 | 
			
		||||
    } catch(Exception ignored) { }
 | 
			
		||||
 | 
			
		||||
    tagName "v${mc_version}-${mod_version}"
 | 
			
		||||
    releaseName "[${mc_version}] ${mod_version}"
 | 
			
		||||
    body {
 | 
			
		||||
        "## " + new File("src/main/resources/data/computercraft/lua/rom/help/whatsnew.txt")
 | 
			
		||||
            .readLines()
 | 
			
		||||
            .takeWhile { it != 'Type "help changelog" to see the full version history.' }
 | 
			
		||||
            .join("\n").trim()
 | 
			
		||||
    }
 | 
			
		||||
    prerelease false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
runClient.outputs.upToDateWhen { false }
 | 
			
		||||
runServer.outputs.upToDateWhen { false }
 | 
			
		||||
def uploadTasks = ["uploadArchives", "curseforge", "githubRelease"]
 | 
			
		||||
uploadTasks.forEach { tasks.getByName(it).dependsOn checkRelease }
 | 
			
		||||
 | 
			
		||||
task uploadAll(dependsOn: uploadTasks) {
 | 
			
		||||
    group "upload"
 | 
			
		||||
    description "Uploads to all repositories (Maven, Curse, GitHub release)"
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										169
									
								
								config/checkstyle/checkstyle.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										169
									
								
								config/checkstyle/checkstyle.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,169 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<!DOCTYPE module PUBLIC
 | 
			
		||||
    "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
 | 
			
		||||
    "https://checkstyle.org/dtds/configuration_1_3.dtd">
 | 
			
		||||
<module name="Checker">
 | 
			
		||||
    <property name="tabWidth" value="4"/>
 | 
			
		||||
    <property name="charset" value="UTF-8" />
 | 
			
		||||
 | 
			
		||||
    <module name="SuppressionFilter">
 | 
			
		||||
        <property name="file" value="config/checkstyle/suppressions.xml" />
 | 
			
		||||
    </module>
 | 
			
		||||
 | 
			
		||||
    <module name="TreeWalker">
 | 
			
		||||
        <!-- Annotations -->
 | 
			
		||||
        <module name="AnnotationLocation" />
 | 
			
		||||
        <module name="AnnotationUseStyle" />
 | 
			
		||||
        <module name="MissingDeprecated" />
 | 
			
		||||
        <module name="MissingOverride" />
 | 
			
		||||
 | 
			
		||||
        <!-- Blocks -->
 | 
			
		||||
        <module name="EmptyBlock" />
 | 
			
		||||
        <module name="EmptyCatchBlock">
 | 
			
		||||
            <property name="exceptionVariableName" value="ignored" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="LeftCurly">
 | 
			
		||||
            <property name="option" value="nl" />
 | 
			
		||||
            <!-- The defaults, minus lambdas. -->
 | 
			
		||||
            <property name="tokens" value="ANNOTATION_DEF,CLASS_DEF,CTOR_DEF,ENUM_CONSTANT_DEF,ENUM_DEF,INTERFACE_DEF,LITERAL_CASE,LITERAL_CATCH,LITERAL_DEFAULT,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_SWITCH,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,METHOD_DEF,OBJBLOCK,STATIC_INIT" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="NeedBraces">
 | 
			
		||||
            <property name="allowSingleLineStatement" value="true"/>
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="RightCurly">
 | 
			
		||||
            <property name="option" value="alone" />
 | 
			
		||||
        </module>
 | 
			
		||||
 | 
			
		||||
        <!-- Class design. As if we've ever followed good practice here. -->
 | 
			
		||||
        <module name="FinalClass" />
 | 
			
		||||
        <module name="InterfaceIsType" />
 | 
			
		||||
        <module name="MutableException" />
 | 
			
		||||
        <module name="OneTopLevelClass" />
 | 
			
		||||
 | 
			
		||||
        <!-- Coding -->
 | 
			
		||||
        <module name="ArrayTrailingComma" />
 | 
			
		||||
        <module name="EqualsHashCode" />
 | 
			
		||||
        <!-- FallThrough does not handle unreachable code well -->
 | 
			
		||||
        <module name="IllegalInstantiation" />
 | 
			
		||||
        <module name="IllegalThrows" />
 | 
			
		||||
        <module name="ModifiedControlVariable" />
 | 
			
		||||
        <module name="NoClone" />
 | 
			
		||||
        <module name="NoFinalizer" />
 | 
			
		||||
        <module name="OneStatementPerLine" />
 | 
			
		||||
        <module name="PackageDeclaration" />
 | 
			
		||||
        <module name="SimplifyBooleanExpression" />
 | 
			
		||||
        <module name="SimplifyBooleanReturn" />
 | 
			
		||||
        <module name="StringLiteralEquality" />
 | 
			
		||||
        <module name="UnnecessaryParentheses" />
 | 
			
		||||
        <module name="UnnecessarySemicolonAfterTypeMemberDeclaration" />
 | 
			
		||||
        <module name="UnnecessarySemicolonInTryWithResources" />
 | 
			
		||||
        <module name="UnnecessarySemicolonInEnumeration" />
 | 
			
		||||
 | 
			
		||||
        <!-- Imports -->
 | 
			
		||||
        <module name="CustomImportOrder" />
 | 
			
		||||
        <module name="IllegalImport" />
 | 
			
		||||
        <module name="RedundantImport" />
 | 
			
		||||
        <module name="UnusedImports" />
 | 
			
		||||
 | 
			
		||||
        <!-- Javadoc -->
 | 
			
		||||
        <!-- TODO: Missing* checks for the dan200.computercraft.api package? -->
 | 
			
		||||
        <module name="AtclauseOrder" />
 | 
			
		||||
        <module name="InvalidJavadocPosition" />
 | 
			
		||||
        <module name="JavadocBlockTagLocation" />
 | 
			
		||||
        <module name="JavadocMethod"/>
 | 
			
		||||
        <module name="JavadocType"/>
 | 
			
		||||
        <module name="JavadocStyle" />
 | 
			
		||||
        <module name="NonEmptyAtclauseDescription" />
 | 
			
		||||
        <module name="SingleLineJavadoc" />
 | 
			
		||||
        <module name="SummaryJavadocCheck"/>
 | 
			
		||||
 | 
			
		||||
        <!-- Misc -->
 | 
			
		||||
        <module name="ArrayTypeStyle" />
 | 
			
		||||
        <module name="CommentsIndentation" />
 | 
			
		||||
        <module name="Indentation" />
 | 
			
		||||
        <module name="OuterTypeFilename" />
 | 
			
		||||
 | 
			
		||||
        <!-- Modifiers -->
 | 
			
		||||
        <module name="ModifierOrder" />
 | 
			
		||||
        <module name="RedundantModifier" />
 | 
			
		||||
 | 
			
		||||
        <!-- Naming -->
 | 
			
		||||
        <module name="ClassTypeParameterName" />
 | 
			
		||||
        <module name="InterfaceTypeParameterName" />
 | 
			
		||||
        <module name="LambdaParameterName" />
 | 
			
		||||
        <module name="LocalFinalVariableName" />
 | 
			
		||||
        <module name="LocalVariableName" />
 | 
			
		||||
        <!-- Allow an optional m_ on private members -->
 | 
			
		||||
        <module name="MemberName">
 | 
			
		||||
            <property name="applyToPrivate" value="false" />
 | 
			
		||||
            <property name="applyToPackage" value="false" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="MemberName">
 | 
			
		||||
            <property name="format" value="^(m_)?[a-z][a-zA-Z0-9]*$" />
 | 
			
		||||
            <property name="applyToPrivate" value="true" />
 | 
			
		||||
            <property name="applyToPackage" value="true" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="MethodName" />
 | 
			
		||||
        <module name="MethodTypeParameterName" />
 | 
			
		||||
        <module name="PackageName">
 | 
			
		||||
            <property name="format" value="^dan200\.computercraf(\.[a-z][a-z0-9]*)*" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="ParameterName" />
 | 
			
		||||
        <module name="StaticVariableName">
 | 
			
		||||
            <property name="format" value="^[a-z][a-zA-Z0-9]*|CAPABILITY(_[A-Z]+)?$" />
 | 
			
		||||
            <property name="applyToPrivate" value="false" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="StaticVariableName">
 | 
			
		||||
            <property name="format" value="^(s_)?[a-z][a-zA-Z0-9]*|CAPABILITY(_[A-Z]+)?$" />
 | 
			
		||||
            <property name="applyToPrivate" value="true" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="TypeName" />
 | 
			
		||||
 | 
			
		||||
        <!-- Whitespace -->
 | 
			
		||||
        <module name="EmptyForInitializerPad"/>
 | 
			
		||||
        <module name="EmptyForIteratorPad">
 | 
			
		||||
            <property name="option" value="space"/>
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="GenericWhitespace" />
 | 
			
		||||
        <module name="MethodParamPad" />
 | 
			
		||||
        <module name="NoLineWrap" />
 | 
			
		||||
        <module name="NoWhitespaceAfter">
 | 
			
		||||
            <property name="tokens" value="AT,INC,DEC,UNARY_MINUS,UNARY_PLUS,BNOT,LNOT,DOT,ARRAY_DECLARATOR,INDEX_OP" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="NoWhitespaceBefore" />
 | 
			
		||||
        <!-- TODO: Decide on an OperatorWrap style. -->
 | 
			
		||||
        <module name="ParenPad">
 | 
			
		||||
            <property name="option" value="space" />
 | 
			
		||||
            <property name="tokens" value="ANNOTATION,ANNOTATION_FIELD_DEF,CTOR_CALL,CTOR_DEF,ENUM_CONSTANT_DEF,LITERAL_CATCH,LITERAL_DO,LITERAL_FOR,LITERAL_IF,LITERAL_NEW,LITERAL_SWITCH,LITERAL_SYNCHRONIZED,LITERAL_WHILE,METHOD_CALL,METHOD_DEF,RESOURCE_SPECIFICATION,SUPER_CTOR_CALL,LAMBDA" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="ParenPad">
 | 
			
		||||
            <property name="option" value="nospace" />
 | 
			
		||||
            <property name="tokens" value="DOT,EXPR,QUESTION" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="SeparatorWrap">
 | 
			
		||||
            <property name="option" value="eol" />
 | 
			
		||||
            <property name="tokens" value="COMMA,SEMI,ELLIPSIS,ARRAY_DECLARATOR,RBRACK,METHOD_REF" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="SeparatorWrap">
 | 
			
		||||
            <property name="option" value="nl" />
 | 
			
		||||
            <property name="tokens" value="DOT,AT" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="SingleSpaceSeparator" />
 | 
			
		||||
        <module name="TypecastParenPad" />
 | 
			
		||||
        <module name="WhitespaceAfter">
 | 
			
		||||
            <property name="tokens" value="COMMA" />
 | 
			
		||||
        </module>
 | 
			
		||||
        <module name="WhitespaceAround">
 | 
			
		||||
            <property name="allowEmptyConstructors" value="true" />
 | 
			
		||||
            <property name="ignoreEnhancedForColon" value="false" />
 | 
			
		||||
            <property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,EQUAL,GE,GT,LAMBDA,LAND,LCURLY,LE,LITERAL_RETURN,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND" />
 | 
			
		||||
        </module>
 | 
			
		||||
    </module>
 | 
			
		||||
 | 
			
		||||
    <module name="FileTabCharacter" />
 | 
			
		||||
    <module name="NewlineAtEndOfFile" />
 | 
			
		||||
    <module name="RegexpSingleline">
 | 
			
		||||
        <property name="format" value="\s+$"/>
 | 
			
		||||
        <property name="message" value="Trailing whitespace"/>
 | 
			
		||||
    </module>
 | 
			
		||||
</module>
 | 
			
		||||
							
								
								
									
										12
									
								
								config/checkstyle/suppressions.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								config/checkstyle/suppressions.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<!DOCTYPE suppressions PUBLIC
 | 
			
		||||
    "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
 | 
			
		||||
    "https://checkstyle.org/dtds/suppressions_1_2.dtd">
 | 
			
		||||
<suppressions>
 | 
			
		||||
    <!-- All the config options and method fields. -->
 | 
			
		||||
    <suppress checks="StaticVariableName" files=".*[\\/]ComputerCraft.java" />
 | 
			
		||||
    <suppress checks="StaticVariableName" files=".*[\\/]ComputerCraftAPI.java" />
 | 
			
		||||
 | 
			
		||||
    <!-- Do not check for missing package Javadoc. -->
 | 
			
		||||
    <suppress checks="JavadocStyle" files=".*[\\/]package-info.java" />
 | 
			
		||||
</suppressions>
 | 
			
		||||
							
								
								
									
										2491
									
								
								config/idea/codeInspectionSettings.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2491
									
								
								config/idea/codeInspectionSettings.xml
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										3
									
								
								config/license/api.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								config/license/api.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
Copyright Daniel Ratcliffe, 2011-${year}. This API may be redistributed unmodified and in full only.
 | 
			
		||||
For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
							
								
								
									
										3
									
								
								config/license/main.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								config/license/main.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
Copyright Daniel Ratcliffe, 2011-${year}. Do not distribute without permission.
 | 
			
		||||
Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
							
								
								
									
										7
									
								
								gradle.properties
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								gradle.properties
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
# Mod properties
 | 
			
		||||
mod_version=1.86.2
 | 
			
		||||
 | 
			
		||||
# Minecraft properties (update mods.toml when changing)
 | 
			
		||||
mc_version=1.14.4
 | 
			
		||||
forge_version=28.1.71
 | 
			
		||||
mappings_version=20191123-1.14.3
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								gradle/wrapper/gradle-wrapper.jar
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								gradle/wrapper/gradle-wrapper.jar
									
									
									
									
										vendored
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								gradle/wrapper/gradle-wrapper.properties
									
									
									
									
										vendored
									
									
								
							@@ -1,5 +1,5 @@
 | 
			
		||||
distributionBase=GRADLE_USER_HOME
 | 
			
		||||
distributionPath=wrapper/dists
 | 
			
		||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
 | 
			
		||||
zipStoreBase=GRADLE_USER_HOME
 | 
			
		||||
zipStorePath=wrapper/dists
 | 
			
		||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-bin.zip
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										28
									
								
								illuaminate.sexp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								illuaminate.sexp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
; -*- mode: Lisp;-*-
 | 
			
		||||
 | 
			
		||||
(sources
 | 
			
		||||
  /src/main/resources/assets/computercraft/lua/bios.lua
 | 
			
		||||
  /src/main/resources/assets/computercraft/lua/rom/
 | 
			
		||||
  /src/test/resources/test-rom)
 | 
			
		||||
 | 
			
		||||
(at /
 | 
			
		||||
  (linters
 | 
			
		||||
    ;; 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))
 | 
			
		||||
 | 
			
		||||
;; 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/assets/computercraft/lua/bios.lua
 | 
			
		||||
   /src/main/resources/assets/computercraft/lua/rom/apis/)
 | 
			
		||||
  (linters -var:unused-global)
 | 
			
		||||
  (lint
 | 
			
		||||
    (allow-toplevel-global true)))
 | 
			
		||||
 | 
			
		||||
;; These warnings are broken right now
 | 
			
		||||
(at (bios.lua worm.lua) (linters -control:unreachable))
 | 
			
		||||
@@ -1 +1 @@
 | 
			
		||||
rootProject.name = 'cc-tweaked'
 | 
			
		||||
rootProject.name = "cc-tweaked-${mc_version}"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,121 +1,53 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.filesystem.IMount;
 | 
			
		||||
import dan200.computercraft.api.filesystem.IWritableMount;
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaAPIFactory;
 | 
			
		||||
import dan200.computercraft.api.media.IMedia;
 | 
			
		||||
import dan200.computercraft.api.media.IMediaProvider;
 | 
			
		||||
import dan200.computercraft.api.network.IPacketNetwork;
 | 
			
		||||
import dan200.computercraft.api.network.wired.IWiredElement;
 | 
			
		||||
import dan200.computercraft.api.network.wired.IWiredNode;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheral;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheralProvider;
 | 
			
		||||
import dan200.computercraft.api.permissions.ITurtlePermissionProvider;
 | 
			
		||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
 | 
			
		||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
 | 
			
		||||
import dan200.computercraft.api.turtle.event.TurtleAction;
 | 
			
		||||
import dan200.computercraft.core.apis.AddressPredicate;
 | 
			
		||||
import dan200.computercraft.core.apis.ApiFactories;
 | 
			
		||||
import dan200.computercraft.core.apis.http.websocket.Websocket;
 | 
			
		||||
import dan200.computercraft.core.filesystem.ComboMount;
 | 
			
		||||
import dan200.computercraft.core.filesystem.FileMount;
 | 
			
		||||
import dan200.computercraft.core.filesystem.JarMount;
 | 
			
		||||
import dan200.computercraft.core.terminal.Terminal;
 | 
			
		||||
import dan200.computercraft.core.tracking.Tracking;
 | 
			
		||||
import dan200.computercraft.shared.*;
 | 
			
		||||
import dan200.computercraft.shared.computer.blocks.BlockCommandComputer;
 | 
			
		||||
import dan200.computercraft.shared.Config;
 | 
			
		||||
import dan200.computercraft.shared.computer.blocks.BlockComputer;
 | 
			
		||||
import dan200.computercraft.shared.computer.blocks.TileComputer;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.ClientComputerRegistry;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.ServerComputer;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.ServerComputerRegistry;
 | 
			
		||||
import dan200.computercraft.shared.computer.items.ItemCommandComputer;
 | 
			
		||||
import dan200.computercraft.shared.computer.items.ItemComputer;
 | 
			
		||||
import dan200.computercraft.shared.media.items.ItemDiskExpanded;
 | 
			
		||||
import dan200.computercraft.shared.media.items.ItemDiskLegacy;
 | 
			
		||||
import dan200.computercraft.shared.media.items.ItemDisk;
 | 
			
		||||
import dan200.computercraft.shared.media.items.ItemPrintout;
 | 
			
		||||
import dan200.computercraft.shared.media.items.ItemTreasureDisk;
 | 
			
		||||
import dan200.computercraft.shared.network.NetworkHandler;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.common.BlockPeripheral;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.common.ItemPeripheral;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.diskdrive.TileDiskDrive;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.diskdrive.BlockDiskDrive;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockWiredModemFull;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.modem.wired.ItemCable;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.modem.wireless.BlockAdvancedModem;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.modem.wireless.ItemAdvancedModem;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.printer.TilePrinter;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.modem.wired.ItemBlockCable;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.modem.wireless.BlockWirelessModem;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.monitor.BlockMonitor;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.printer.BlockPrinter;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.speaker.BlockSpeaker;
 | 
			
		||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
 | 
			
		||||
import dan200.computercraft.shared.pocket.peripherals.PocketModem;
 | 
			
		||||
import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker;
 | 
			
		||||
import dan200.computercraft.shared.proxy.ICCTurtleProxy;
 | 
			
		||||
import dan200.computercraft.shared.proxy.IComputerCraftProxy;
 | 
			
		||||
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
 | 
			
		||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
 | 
			
		||||
import dan200.computercraft.shared.turtle.items.ItemTurtleAdvanced;
 | 
			
		||||
import dan200.computercraft.shared.turtle.items.ItemTurtleLegacy;
 | 
			
		||||
import dan200.computercraft.shared.turtle.items.ItemTurtleNormal;
 | 
			
		||||
import dan200.computercraft.shared.turtle.items.ItemTurtle;
 | 
			
		||||
import dan200.computercraft.shared.turtle.upgrades.*;
 | 
			
		||||
import dan200.computercraft.shared.util.CreativeTabMain;
 | 
			
		||||
import dan200.computercraft.shared.util.IDAssigner;
 | 
			
		||||
import dan200.computercraft.shared.util.IoUtil;
 | 
			
		||||
import dan200.computercraft.shared.wired.CapabilityWiredElement;
 | 
			
		||||
import dan200.computercraft.shared.wired.WiredNode;
 | 
			
		||||
import net.minecraft.entity.player.EntityPlayer;
 | 
			
		||||
import net.minecraft.item.ItemBlock;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraft.server.MinecraftServer;
 | 
			
		||||
import net.minecraft.tileentity.TileEntity;
 | 
			
		||||
import net.minecraft.util.EnumFacing;
 | 
			
		||||
import net.minecraft.util.EnumHand;
 | 
			
		||||
import net.minecraft.util.math.BlockPos;
 | 
			
		||||
import net.minecraft.world.IBlockAccess;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
import net.minecraftforge.common.DimensionManager;
 | 
			
		||||
import net.minecraftforge.fml.common.FMLCommonHandler;
 | 
			
		||||
import net.minecraft.resources.IReloadableResourceManager;
 | 
			
		||||
import net.minecraft.util.ResourceLocation;
 | 
			
		||||
import net.minecraftforge.fml.common.Mod;
 | 
			
		||||
import net.minecraftforge.fml.common.SidedProxy;
 | 
			
		||||
import net.minecraftforge.fml.common.event.*;
 | 
			
		||||
import net.minecraftforge.fml.relauncher.Side;
 | 
			
		||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
 | 
			
		||||
import org.apache.logging.log4j.LogManager;
 | 
			
		||||
import org.apache.logging.log4j.Logger;
 | 
			
		||||
 | 
			
		||||
import java.io.*;
 | 
			
		||||
import java.net.MalformedURLException;
 | 
			
		||||
import java.net.URISyntaxException;
 | 
			
		||||
import java.net.URL;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.io.InputStream;
 | 
			
		||||
import java.util.EnumSet;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.zip.ZipEntry;
 | 
			
		||||
import java.util.zip.ZipFile;
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
 | 
			
		||||
@Mod(
 | 
			
		||||
    modid = ComputerCraft.MOD_ID, name = "CC: Tweaked", version = "${version}",
 | 
			
		||||
    guiFactory = "dan200.computercraft.client.gui.GuiConfigCC$Factory",
 | 
			
		||||
    dependencies = "required:forge@[14.23.4.2746,)"
 | 
			
		||||
)
 | 
			
		||||
public class ComputerCraft
 | 
			
		||||
@Mod( ComputerCraft.MOD_ID )
 | 
			
		||||
public final class ComputerCraft
 | 
			
		||||
{
 | 
			
		||||
    public static final String MOD_ID = "computercraft";
 | 
			
		||||
 | 
			
		||||
    // GUI IDs
 | 
			
		||||
    public static final int diskDriveGUIID = 100;
 | 
			
		||||
    public static final int computerGUIID = 101;
 | 
			
		||||
    public static final int printerGUIID = 102;
 | 
			
		||||
    public static final int turtleGUIID = 103;
 | 
			
		||||
    // ComputerCraftEdu uses ID 104
 | 
			
		||||
    public static final int printoutGUIID = 105;
 | 
			
		||||
    public static final int pocketComputerGUIID = 106;
 | 
			
		||||
    public static final int viewComputerGUIID = 110;
 | 
			
		||||
    public static final int DATAFIXER_VERSION = 0;
 | 
			
		||||
 | 
			
		||||
    // Configuration options
 | 
			
		||||
    public static final String[] DEFAULT_HTTP_WHITELIST = new String[] { "*" };
 | 
			
		||||
@@ -133,9 +65,12 @@ public class ComputerCraft
 | 
			
		||||
    public static boolean disable_lua51_features = false;
 | 
			
		||||
    public static String default_computer_settings = "";
 | 
			
		||||
    public static boolean debug_enable = true;
 | 
			
		||||
    public static int computer_threads = 1;
 | 
			
		||||
    public static boolean logPeripheralErrors = false;
 | 
			
		||||
 | 
			
		||||
    public static int computer_threads = 1;
 | 
			
		||||
    public static long maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos( 10 );
 | 
			
		||||
    public static long maxMainComputerTime = TimeUnit.MILLISECONDS.toNanos( 5 );
 | 
			
		||||
 | 
			
		||||
    public static boolean http_enable = true;
 | 
			
		||||
    public static boolean http_websocket_enable = true;
 | 
			
		||||
    public static AddressPredicate http_whitelist = new AddressPredicate( DEFAULT_HTTP_WHITELIST );
 | 
			
		||||
@@ -172,48 +107,56 @@ public class ComputerCraft
 | 
			
		||||
    public static final int terminalHeight_pocketComputer = 20;
 | 
			
		||||
 | 
			
		||||
    // Blocks and Items
 | 
			
		||||
    public static class Blocks
 | 
			
		||||
    public static final class Blocks
 | 
			
		||||
    {
 | 
			
		||||
        public static BlockComputer computer;
 | 
			
		||||
        public static BlockCommandComputer commandComputer;
 | 
			
		||||
        public static BlockComputer computerNormal;
 | 
			
		||||
        public static BlockComputer computerAdvanced;
 | 
			
		||||
        public static BlockComputer computerCommand;
 | 
			
		||||
 | 
			
		||||
        public static BlockTurtle turtle;
 | 
			
		||||
        public static BlockTurtle turtleExpanded;
 | 
			
		||||
        public static BlockTurtle turtleNormal;
 | 
			
		||||
        public static BlockTurtle turtleAdvanced;
 | 
			
		||||
 | 
			
		||||
        public static BlockPeripheral peripheral;
 | 
			
		||||
        public static BlockCable cable;
 | 
			
		||||
        public static BlockAdvancedModem advancedModem;
 | 
			
		||||
        public static BlockSpeaker speaker;
 | 
			
		||||
        public static BlockDiskDrive diskDrive;
 | 
			
		||||
        public static BlockPrinter printer;
 | 
			
		||||
 | 
			
		||||
        public static BlockMonitor monitorNormal;
 | 
			
		||||
        public static BlockMonitor monitorAdvanced;
 | 
			
		||||
 | 
			
		||||
        public static BlockWirelessModem wirelessModemNormal;
 | 
			
		||||
        public static BlockWirelessModem wirelessModemAdvanced;
 | 
			
		||||
 | 
			
		||||
        public static BlockWiredModemFull wiredModemFull;
 | 
			
		||||
        public static BlockCable cable;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static class Items
 | 
			
		||||
    public static final class Items
 | 
			
		||||
    {
 | 
			
		||||
        public static ItemComputer computer;
 | 
			
		||||
        public static ItemCommandComputer commandComputer;
 | 
			
		||||
        public static ItemComputer computerNormal;
 | 
			
		||||
        public static ItemComputer computerAdvanced;
 | 
			
		||||
        public static ItemComputer computerCommand;
 | 
			
		||||
 | 
			
		||||
        public static ItemTurtleLegacy turtle;
 | 
			
		||||
        public static ItemTurtleNormal turtleExpanded;
 | 
			
		||||
        public static ItemTurtleAdvanced turtleAdvanced;
 | 
			
		||||
        public static ItemPocketComputer pocketComputerNormal;
 | 
			
		||||
        public static ItemPocketComputer pocketComputerAdvanced;
 | 
			
		||||
 | 
			
		||||
        public static ItemPocketComputer pocketComputer;
 | 
			
		||||
        public static ItemTurtle turtleNormal;
 | 
			
		||||
        public static ItemTurtle turtleAdvanced;
 | 
			
		||||
 | 
			
		||||
        public static ItemDiskLegacy disk;
 | 
			
		||||
        public static ItemDiskExpanded diskExpanded;
 | 
			
		||||
        public static ItemDisk disk;
 | 
			
		||||
        public static ItemTreasureDisk treasureDisk;
 | 
			
		||||
 | 
			
		||||
        public static ItemPrintout printout;
 | 
			
		||||
        public static ItemPrintout printedPage;
 | 
			
		||||
        public static ItemPrintout printedPages;
 | 
			
		||||
        public static ItemPrintout printedBook;
 | 
			
		||||
 | 
			
		||||
        public static ItemPeripheral peripheral;
 | 
			
		||||
        public static ItemAdvancedModem advancedModem;
 | 
			
		||||
        public static ItemCable cable;
 | 
			
		||||
        public static ItemBlock wiredModemFull;
 | 
			
		||||
        public static ItemBlockCable.Cable cable;
 | 
			
		||||
        public static ItemBlockCable.WiredModem wiredModem;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static class TurtleUpgrades
 | 
			
		||||
    public static final class TurtleUpgrades
 | 
			
		||||
    {
 | 
			
		||||
        public static TurtleModem wirelessModem;
 | 
			
		||||
        public static TurtleModem advancedModem;
 | 
			
		||||
        public static TurtleModem wirelessModemNormal;
 | 
			
		||||
        public static TurtleModem wirelessModemAdvanced;
 | 
			
		||||
        public static TurtleSpeaker speaker;
 | 
			
		||||
 | 
			
		||||
        public static TurtleCraftingTable craftingTable;
 | 
			
		||||
@@ -224,99 +167,23 @@ public class ComputerCraft
 | 
			
		||||
        public static TurtleHoe diamondHoe;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static class PocketUpgrades
 | 
			
		||||
    public static final class PocketUpgrades
 | 
			
		||||
    {
 | 
			
		||||
        public static PocketModem wirelessModem;
 | 
			
		||||
        public static PocketModem advancedModem;
 | 
			
		||||
        public static PocketModem wirelessModemNormal;
 | 
			
		||||
        public static PocketModem wirelessModemAdvanced;
 | 
			
		||||
        public static PocketSpeaker speaker;
 | 
			
		||||
 | 
			
		||||
        @Deprecated
 | 
			
		||||
        public static PocketSpeaker pocketSpeaker;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static class Upgrades
 | 
			
		||||
    {
 | 
			
		||||
        public static TurtleModem advancedModem;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Registries
 | 
			
		||||
    public static final ClientComputerRegistry clientComputerRegistry = new ClientComputerRegistry();
 | 
			
		||||
    public static final ServerComputerRegistry serverComputerRegistry = new ServerComputerRegistry();
 | 
			
		||||
 | 
			
		||||
    // Creative
 | 
			
		||||
    public static CreativeTabMain mainCreativeTab;
 | 
			
		||||
 | 
			
		||||
    // Logging
 | 
			
		||||
    public static Logger log;
 | 
			
		||||
    public static final Logger log = LogManager.getLogger( MOD_ID );
 | 
			
		||||
 | 
			
		||||
    // Peripheral providers. This is still here to ensure compatibility with Plethora and Computronics
 | 
			
		||||
    public static List<IPeripheralProvider> peripheralProviders = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
    // Implementation
 | 
			
		||||
    @Mod.Instance( value = ComputerCraft.MOD_ID )
 | 
			
		||||
    public static ComputerCraft instance;
 | 
			
		||||
 | 
			
		||||
    @SidedProxy(
 | 
			
		||||
        clientSide = "dan200.computercraft.client.proxy.ComputerCraftProxyClient",
 | 
			
		||||
        serverSide = "dan200.computercraft.shared.proxy.ComputerCraftProxyCommon"
 | 
			
		||||
    )
 | 
			
		||||
    private static IComputerCraftProxy proxy;
 | 
			
		||||
 | 
			
		||||
    @SidedProxy(
 | 
			
		||||
        clientSide = "dan200.computercraft.client.proxy.CCTurtleProxyClient",
 | 
			
		||||
        serverSide = "dan200.computercraft.shared.proxy.CCTurtleProxyCommon"
 | 
			
		||||
    )
 | 
			
		||||
    private static ICCTurtleProxy turtleProxy;
 | 
			
		||||
 | 
			
		||||
    @Mod.EventHandler
 | 
			
		||||
    public void preInit( FMLPreInitializationEvent event )
 | 
			
		||||
    public ComputerCraft()
 | 
			
		||||
    {
 | 
			
		||||
        log = event.getModLog();
 | 
			
		||||
 | 
			
		||||
        // Load config
 | 
			
		||||
        Config.load( event.getSuggestedConfigurationFile() );
 | 
			
		||||
 | 
			
		||||
        // Setup network
 | 
			
		||||
        NetworkHandler.setup();
 | 
			
		||||
 | 
			
		||||
        proxy.preInit();
 | 
			
		||||
        turtleProxy.preInit();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Mod.EventHandler
 | 
			
		||||
    public void init( FMLInitializationEvent event )
 | 
			
		||||
    {
 | 
			
		||||
        proxy.init();
 | 
			
		||||
        turtleProxy.init();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Mod.EventHandler
 | 
			
		||||
    public void onServerStarting( FMLServerStartingEvent event )
 | 
			
		||||
    {
 | 
			
		||||
        proxy.initServer( event.getServer() );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Mod.EventHandler
 | 
			
		||||
    public void onServerStart( FMLServerStartedEvent event )
 | 
			
		||||
    {
 | 
			
		||||
        if( FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER )
 | 
			
		||||
        {
 | 
			
		||||
            ComputerCraft.serverComputerRegistry.reset();
 | 
			
		||||
            WirelessNetwork.resetNetworks();
 | 
			
		||||
            Tracking.reset();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Mod.EventHandler
 | 
			
		||||
    public void onServerStopped( FMLServerStoppedEvent event )
 | 
			
		||||
    {
 | 
			
		||||
        if( FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER )
 | 
			
		||||
        {
 | 
			
		||||
            ComputerCraft.serverComputerRegistry.reset();
 | 
			
		||||
            WirelessNetwork.resetNetworks();
 | 
			
		||||
            Tracking.reset();
 | 
			
		||||
        }
 | 
			
		||||
        Config.load();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String getVersion()
 | 
			
		||||
@@ -324,411 +191,16 @@ public class ComputerCraft
 | 
			
		||||
        return "${version}";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void openDiskDriveGUI( EntityPlayer player, TileDiskDrive drive )
 | 
			
		||||
    {
 | 
			
		||||
        BlockPos pos = drive.getPos();
 | 
			
		||||
        player.openGui( ComputerCraft.instance, ComputerCraft.diskDriveGUIID, player.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ() );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void openComputerGUI( EntityPlayer player, TileComputer computer )
 | 
			
		||||
    {
 | 
			
		||||
        BlockPos pos = computer.getPos();
 | 
			
		||||
        player.openGui( ComputerCraft.instance, ComputerCraft.computerGUIID, player.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ() );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void openPrinterGUI( EntityPlayer player, TilePrinter printer )
 | 
			
		||||
    {
 | 
			
		||||
        BlockPos pos = printer.getPos();
 | 
			
		||||
        player.openGui( ComputerCraft.instance, ComputerCraft.printerGUIID, player.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ() );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void openTurtleGUI( EntityPlayer player, TileTurtle turtle )
 | 
			
		||||
    {
 | 
			
		||||
        BlockPos pos = turtle.getPos();
 | 
			
		||||
        player.openGui( instance, ComputerCraft.turtleGUIID, player.getEntityWorld(), pos.getX(), pos.getY(), pos.getZ() );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void openPrintoutGUI( EntityPlayer player, EnumHand hand )
 | 
			
		||||
    {
 | 
			
		||||
        player.openGui( ComputerCraft.instance, ComputerCraft.printoutGUIID, player.getEntityWorld(), hand.ordinal(), 0, 0 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void openPocketComputerGUI( EntityPlayer player, EnumHand hand )
 | 
			
		||||
    {
 | 
			
		||||
        player.openGui( ComputerCraft.instance, ComputerCraft.pocketComputerGUIID, player.getEntityWorld(), hand.ordinal(), 0, 0 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void openComputerGUI( EntityPlayer player, ServerComputer computer )
 | 
			
		||||
    {
 | 
			
		||||
        ComputerFamily family = computer.getFamily();
 | 
			
		||||
        int width = 0, height = 0;
 | 
			
		||||
        Terminal terminal = computer.getTerminal();
 | 
			
		||||
        if( terminal != null )
 | 
			
		||||
        {
 | 
			
		||||
            width = terminal.getWidth();
 | 
			
		||||
            height = terminal.getHeight();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Pack useful terminal information into the various coordinate bits.
 | 
			
		||||
        // These are extracted in ComputerCraftProxyCommon.getClientGuiElement
 | 
			
		||||
        player.openGui( ComputerCraft.instance, ComputerCraft.viewComputerGUIID, player.getEntityWorld(),
 | 
			
		||||
            computer.getInstanceID(), family.ordinal(), (width & 0xFFFF) << 16 | (height & 0xFFFF)
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static File getBaseDir()
 | 
			
		||||
    {
 | 
			
		||||
        return FMLCommonHandler.instance().getMinecraftServerInstance().getDataDirectory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static File getResourcePackDir()
 | 
			
		||||
    {
 | 
			
		||||
        return new File( getBaseDir(), "resourcepacks" );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean canPlayerUseCommands( EntityPlayer player )
 | 
			
		||||
    {
 | 
			
		||||
        MinecraftServer server = player.getServer();
 | 
			
		||||
        if( server != null )
 | 
			
		||||
        {
 | 
			
		||||
            return server.getPlayerList().canSendCommands( player.getGameProfile() );
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static void registerPermissionProvider( ITurtlePermissionProvider provider )
 | 
			
		||||
    {
 | 
			
		||||
        TurtlePermissions.register( provider );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static void registerPocketUpgrade( IPocketUpgrade upgrade )
 | 
			
		||||
    {
 | 
			
		||||
        dan200.computercraft.shared.PocketUpgrades.register( upgrade );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static void registerPeripheralProvider( IPeripheralProvider provider )
 | 
			
		||||
    {
 | 
			
		||||
        Peripherals.register( provider );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static void registerBundledRedstoneProvider( IBundledRedstoneProvider provider )
 | 
			
		||||
    {
 | 
			
		||||
        BundledRedstone.register( provider );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static void registerMediaProvider( IMediaProvider provider )
 | 
			
		||||
    {
 | 
			
		||||
        MediaProviders.register( provider );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static void registerAPIFactory( ILuaAPIFactory factory )
 | 
			
		||||
    {
 | 
			
		||||
        ApiFactories.register( factory );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static IWiredNode createWiredNodeForElement( IWiredElement element )
 | 
			
		||||
    {
 | 
			
		||||
        return new WiredNode( element );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static IWiredElement getWiredElementAt( IBlockAccess world, BlockPos pos, EnumFacing side )
 | 
			
		||||
    {
 | 
			
		||||
        TileEntity tile = world.getTileEntity( pos );
 | 
			
		||||
        return tile != null && tile.hasCapability( CapabilityWiredElement.CAPABILITY, side )
 | 
			
		||||
            ? tile.getCapability( CapabilityWiredElement.CAPABILITY, side )
 | 
			
		||||
            : null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static int getDefaultBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side )
 | 
			
		||||
    {
 | 
			
		||||
        return BundledRedstone.getDefaultOutput( world, pos, side );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static IPacketNetwork getWirelessNetwork()
 | 
			
		||||
    {
 | 
			
		||||
        return WirelessNetwork.getUniversal();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static int createUniqueNumberedSaveDir( World world, String parentSubPath )
 | 
			
		||||
    {
 | 
			
		||||
        return IDAssigner.getNextIDFromDirectory( parentSubPath );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static IWritableMount createSaveDirMount( World world, String subPath, long capacity )
 | 
			
		||||
    public static InputStream getResourceFile( String domain, String subPath )
 | 
			
		||||
    {
 | 
			
		||||
        IReloadableResourceManager manager = ServerLifecycleHooks.getCurrentServer().getResourceManager();
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            return new FileMount( new File( getWorldDir(), subPath ), capacity );
 | 
			
		||||
            return manager.getResource( new ResourceLocation( domain, subPath ) ).getInputStream();
 | 
			
		||||
        }
 | 
			
		||||
        catch( Exception e )
 | 
			
		||||
        catch( IOException ignored )
 | 
			
		||||
        {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static IMount createResourceMount( Class<?> modClass, String domain, String subPath )
 | 
			
		||||
    {
 | 
			
		||||
        // Start building list of mounts
 | 
			
		||||
        List<IMount> mounts = new ArrayList<>();
 | 
			
		||||
        subPath = "assets/" + domain + "/" + subPath;
 | 
			
		||||
 | 
			
		||||
        // Mount from debug dir
 | 
			
		||||
        File codeDir = getDebugCodeDir( modClass );
 | 
			
		||||
        if( codeDir != null )
 | 
			
		||||
        {
 | 
			
		||||
            File subResource = new File( codeDir, subPath );
 | 
			
		||||
            if( subResource.exists() )
 | 
			
		||||
            {
 | 
			
		||||
                IMount resourcePackMount = new FileMount( subResource, 0 );
 | 
			
		||||
                mounts.add( resourcePackMount );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Mount from mod jar
 | 
			
		||||
        File modJar = getContainingJar( modClass );
 | 
			
		||||
        if( modJar != null )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                mounts.add( new JarMount( modJar, subPath ) );
 | 
			
		||||
            }
 | 
			
		||||
            catch( IOException | RuntimeException e )
 | 
			
		||||
            {
 | 
			
		||||
                ComputerCraft.log.error( "Could not load mount from mod jar", e );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Mount from resource packs
 | 
			
		||||
        File resourcePackDir = getResourcePackDir();
 | 
			
		||||
        if( resourcePackDir.exists() && resourcePackDir.isDirectory() )
 | 
			
		||||
        {
 | 
			
		||||
            String[] resourcePacks = resourcePackDir.list();
 | 
			
		||||
            for( String resourcePackName : resourcePacks )
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    File resourcePack = new File( resourcePackDir, resourcePackName );
 | 
			
		||||
                    if( !resourcePack.isDirectory() )
 | 
			
		||||
                    {
 | 
			
		||||
                        // Mount a resource pack from a jar
 | 
			
		||||
                        mounts.add( new JarMount( resourcePack, subPath ) );
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        // Mount a resource pack from a folder
 | 
			
		||||
                        File subResource = new File( resourcePack, subPath );
 | 
			
		||||
                        if( subResource.exists() ) mounts.add( new FileMount( subResource, 0 ) );
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                catch( IOException | RuntimeException e )
 | 
			
		||||
                {
 | 
			
		||||
                    ComputerCraft.log.error( "Could not load resource pack '" + resourcePackName + "'", e );
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Return the combination of all the mounts found
 | 
			
		||||
        if( mounts.size() >= 2 )
 | 
			
		||||
        {
 | 
			
		||||
            IMount[] mountArray = new IMount[mounts.size()];
 | 
			
		||||
            mounts.toArray( mountArray );
 | 
			
		||||
            return new ComboMount( mountArray );
 | 
			
		||||
        }
 | 
			
		||||
        else if( mounts.size() == 1 )
 | 
			
		||||
        {
 | 
			
		||||
            return mounts.get( 0 );
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static InputStream getResourceFile( Class<?> modClass, String domain, String subPath )
 | 
			
		||||
    {
 | 
			
		||||
        // Start searching in possible locations
 | 
			
		||||
        subPath = "assets/" + domain + "/" + subPath;
 | 
			
		||||
 | 
			
		||||
        // Look in resource packs
 | 
			
		||||
        File resourcePackDir = getResourcePackDir();
 | 
			
		||||
        if( resourcePackDir.exists() && resourcePackDir.isDirectory() )
 | 
			
		||||
        {
 | 
			
		||||
            String[] resourcePacks = resourcePackDir.list();
 | 
			
		||||
            for( String resourcePackPath : resourcePacks )
 | 
			
		||||
            {
 | 
			
		||||
                File resourcePack = new File( resourcePackDir, resourcePackPath );
 | 
			
		||||
                if( resourcePack.isDirectory() )
 | 
			
		||||
                {
 | 
			
		||||
                    // Mount a resource pack from a folder
 | 
			
		||||
                    File subResource = new File( resourcePack, subPath );
 | 
			
		||||
                    if( subResource.exists() && subResource.isFile() )
 | 
			
		||||
                    {
 | 
			
		||||
                        try
 | 
			
		||||
                        {
 | 
			
		||||
                            return new FileInputStream( subResource );
 | 
			
		||||
                        }
 | 
			
		||||
                        catch( FileNotFoundException ignored )
 | 
			
		||||
                        {
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    ZipFile zipFile = null;
 | 
			
		||||
                    try
 | 
			
		||||
                    {
 | 
			
		||||
                        final ZipFile zip = zipFile = new ZipFile( resourcePack );
 | 
			
		||||
                        ZipEntry entry = zipFile.getEntry( subPath );
 | 
			
		||||
                        if( entry != null )
 | 
			
		||||
                        {
 | 
			
		||||
                            // Return a custom InputStream which will close the original zip when finished.
 | 
			
		||||
                            return new FilterInputStream( zipFile.getInputStream( entry ) )
 | 
			
		||||
                            {
 | 
			
		||||
                                @Override
 | 
			
		||||
                                public void close() throws IOException
 | 
			
		||||
                                {
 | 
			
		||||
                                    super.close();
 | 
			
		||||
                                    zip.close();
 | 
			
		||||
                                }
 | 
			
		||||
                            };
 | 
			
		||||
                        }
 | 
			
		||||
                        else
 | 
			
		||||
                        {
 | 
			
		||||
                            IoUtil.closeQuietly( zipFile );
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    catch( IOException e )
 | 
			
		||||
                    {
 | 
			
		||||
                        if( zipFile != null ) IoUtil.closeQuietly( zipFile );
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Look in debug dir
 | 
			
		||||
        File codeDir = getDebugCodeDir( modClass );
 | 
			
		||||
        if( codeDir != null )
 | 
			
		||||
        {
 | 
			
		||||
            File subResource = new File( codeDir, subPath );
 | 
			
		||||
            if( subResource.exists() && subResource.isFile() )
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    return new FileInputStream( subResource );
 | 
			
		||||
                }
 | 
			
		||||
                catch( FileNotFoundException ignored )
 | 
			
		||||
                {
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Look in class loader
 | 
			
		||||
        return modClass.getClassLoader().getResourceAsStream( subPath );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static File getContainingJar( Class<?> modClass )
 | 
			
		||||
    {
 | 
			
		||||
        String path = modClass.getProtectionDomain().getCodeSource().getLocation().getPath();
 | 
			
		||||
        int bangIndex = path.indexOf( "!" );
 | 
			
		||||
        if( bangIndex >= 0 )
 | 
			
		||||
        {
 | 
			
		||||
            path = path.substring( 0, bangIndex );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        URL url;
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            url = new URL( path );
 | 
			
		||||
        }
 | 
			
		||||
        catch( MalformedURLException e1 )
 | 
			
		||||
        {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        File file;
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            file = new File( url.toURI() );
 | 
			
		||||
        }
 | 
			
		||||
        catch( URISyntaxException e )
 | 
			
		||||
        {
 | 
			
		||||
            file = new File( url.getPath() );
 | 
			
		||||
        }
 | 
			
		||||
        return file;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static File getDebugCodeDir( Class<?> modClass )
 | 
			
		||||
    {
 | 
			
		||||
        String path = modClass.getProtectionDomain().getCodeSource().getLocation().getPath();
 | 
			
		||||
        int bangIndex = path.indexOf( "!" );
 | 
			
		||||
        return bangIndex >= 0 ? null : new File( new File( path ).getParentFile(), "../.." );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static void registerTurtleUpgrade( ITurtleUpgrade upgrade )
 | 
			
		||||
    {
 | 
			
		||||
        dan200.computercraft.shared.TurtleUpgrades.register( upgrade );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static File getWorldDir()
 | 
			
		||||
    {
 | 
			
		||||
        return DimensionManager.getCurrentSaveRootDirectory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //region Compatibility
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static File getWorldDir( World world )
 | 
			
		||||
    {
 | 
			
		||||
        return DimensionManager.getCurrentSaveRootDirectory();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static IMedia getMedia( ItemStack stack )
 | 
			
		||||
    {
 | 
			
		||||
        return MediaProviders.get( stack );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static IPocketUpgrade getPocketUpgrade( ItemStack stack )
 | 
			
		||||
    {
 | 
			
		||||
        return dan200.computercraft.shared.PocketUpgrades.get( stack );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static ITurtleUpgrade getTurtleUpgrade( ItemStack stack )
 | 
			
		||||
    {
 | 
			
		||||
        return dan200.computercraft.shared.TurtleUpgrades.get( stack );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static IPocketUpgrade getPocketUpgrade( String id )
 | 
			
		||||
    {
 | 
			
		||||
        return dan200.computercraft.shared.PocketUpgrades.get( id );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static ITurtleUpgrade getTurtleUpgrade( String id )
 | 
			
		||||
    {
 | 
			
		||||
        return dan200.computercraft.shared.TurtleUpgrades.get( id );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static IPeripheral getPeripheralAt( World world, BlockPos pos, EnumFacing side )
 | 
			
		||||
    {
 | 
			
		||||
        return Peripherals.getPeripheral( world, pos, side );
 | 
			
		||||
    }
 | 
			
		||||
    //endregion
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										152
									
								
								src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										152
									
								
								src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,152 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
package dan200.computercraft;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.MapMaker;
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI.IComputerCraftAPI;
 | 
			
		||||
import dan200.computercraft.api.filesystem.IMount;
 | 
			
		||||
import dan200.computercraft.api.filesystem.IWritableMount;
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaAPIFactory;
 | 
			
		||||
import dan200.computercraft.api.media.IMediaProvider;
 | 
			
		||||
import dan200.computercraft.api.network.IPacketNetwork;
 | 
			
		||||
import dan200.computercraft.api.network.wired.IWiredElement;
 | 
			
		||||
import dan200.computercraft.api.network.wired.IWiredNode;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheralProvider;
 | 
			
		||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
 | 
			
		||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
 | 
			
		||||
import dan200.computercraft.core.apis.ApiFactories;
 | 
			
		||||
import dan200.computercraft.core.filesystem.FileMount;
 | 
			
		||||
import dan200.computercraft.core.filesystem.ResourceMount;
 | 
			
		||||
import dan200.computercraft.shared.*;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
 | 
			
		||||
import dan200.computercraft.shared.util.IDAssigner;
 | 
			
		||||
import dan200.computercraft.shared.wired.CapabilityWiredElement;
 | 
			
		||||
import dan200.computercraft.shared.wired.WiredNode;
 | 
			
		||||
import net.minecraft.resources.IReloadableResourceManager;
 | 
			
		||||
import net.minecraft.tileentity.TileEntity;
 | 
			
		||||
import net.minecraft.util.Direction;
 | 
			
		||||
import net.minecraft.util.ResourceLocation;
 | 
			
		||||
import net.minecraft.util.math.BlockPos;
 | 
			
		||||
import net.minecraft.world.IBlockReader;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
import net.minecraftforge.common.util.LazyOptional;
 | 
			
		||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.lang.ref.WeakReference;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
public final class ComputerCraftAPIImpl implements IComputerCraftAPI
 | 
			
		||||
{
 | 
			
		||||
    public static final ComputerCraftAPIImpl INSTANCE = new ComputerCraftAPIImpl();
 | 
			
		||||
 | 
			
		||||
    private ComputerCraftAPIImpl()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private WeakReference<IReloadableResourceManager> currentResources;
 | 
			
		||||
    private final Map<ResourceLocation, ResourceMount> mountCache = new MapMaker().weakValues().concurrencyLevel( 1 ).makeMap();
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getInstalledVersion()
 | 
			
		||||
    {
 | 
			
		||||
        return "${version}";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
 | 
			
		||||
    {
 | 
			
		||||
        return IDAssigner.getNextId( parentSubPath );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            return new FileMount( new File( IDAssigner.getDir(), subPath ), capacity );
 | 
			
		||||
        }
 | 
			
		||||
        catch( Exception e )
 | 
			
		||||
        {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath )
 | 
			
		||||
    {
 | 
			
		||||
        IReloadableResourceManager manager = ServerLifecycleHooks.getCurrentServer().getResourceManager();
 | 
			
		||||
        ResourceMount mount = ResourceMount.get( domain, subPath, manager );
 | 
			
		||||
        return mount.exists( "" ) ? mount : null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void registerPeripheralProvider( @Nonnull IPeripheralProvider provider )
 | 
			
		||||
    {
 | 
			
		||||
        Peripherals.register( provider );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade )
 | 
			
		||||
    {
 | 
			
		||||
        TurtleUpgrades.register( upgrade );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider )
 | 
			
		||||
    {
 | 
			
		||||
        BundledRedstone.register( provider );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
 | 
			
		||||
    {
 | 
			
		||||
        return BundledRedstone.getDefaultOutput( world, pos, side );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void registerMediaProvider( @Nonnull IMediaProvider provider )
 | 
			
		||||
    {
 | 
			
		||||
        MediaProviders.register( provider );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
 | 
			
		||||
    {
 | 
			
		||||
        PocketUpgrades.register( upgrade );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @Override
 | 
			
		||||
    public IPacketNetwork getWirelessNetwork()
 | 
			
		||||
    {
 | 
			
		||||
        return WirelessNetwork.getUniversal();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void registerAPIFactory( @Nonnull ILuaAPIFactory factory )
 | 
			
		||||
    {
 | 
			
		||||
        ApiFactories.register( factory );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @Override
 | 
			
		||||
    public IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element )
 | 
			
		||||
    {
 | 
			
		||||
        return new WiredNode( element );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @Override
 | 
			
		||||
    public LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction side )
 | 
			
		||||
    {
 | 
			
		||||
        TileEntity tile = world.getTileEntity( pos );
 | 
			
		||||
        return tile == null ? LazyOptional.empty() : tile.getCapability( CapabilityWiredElement.CAPABILITY, side );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,79 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle.ITurtleUpgrade;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleUpgradeType;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraft.util.IItemProvider;
 | 
			
		||||
import net.minecraft.util.ResourceLocation;
 | 
			
		||||
import net.minecraft.util.Util;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A base class for {@link ITurtleUpgrade}s.
 | 
			
		||||
 *
 | 
			
		||||
 * One does not have to use this, but it does provide a convenient template.
 | 
			
		||||
 */
 | 
			
		||||
public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
 | 
			
		||||
{
 | 
			
		||||
    private final ResourceLocation id;
 | 
			
		||||
    private final TurtleUpgradeType type;
 | 
			
		||||
    private final String adjective;
 | 
			
		||||
    private final ItemStack stack;
 | 
			
		||||
 | 
			
		||||
    protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, String adjective, ItemStack stack )
 | 
			
		||||
    {
 | 
			
		||||
        this.id = id;
 | 
			
		||||
        this.type = type;
 | 
			
		||||
        this.adjective = adjective;
 | 
			
		||||
        this.stack = stack;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, String adjective, IItemProvider item )
 | 
			
		||||
    {
 | 
			
		||||
        this( id, type, adjective, new ItemStack( item ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, ItemStack stack )
 | 
			
		||||
    {
 | 
			
		||||
        this( id, type, Util.makeTranslationKey( "upgrade", id ) + ".adjective", stack );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, IItemProvider item )
 | 
			
		||||
    {
 | 
			
		||||
        this( id, type, new ItemStack( item ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @Override
 | 
			
		||||
    public final ResourceLocation getUpgradeID()
 | 
			
		||||
    {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @Override
 | 
			
		||||
    public final String getUnlocalisedAdjective()
 | 
			
		||||
    {
 | 
			
		||||
        return adjective;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @Override
 | 
			
		||||
    public final TurtleUpgradeType getType()
 | 
			
		||||
    {
 | 
			
		||||
        return type;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @Override
 | 
			
		||||
    public final ItemStack getCraftingItem()
 | 
			
		||||
    {
 | 
			
		||||
        return stack;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
@@ -17,48 +16,30 @@ import dan200.computercraft.api.network.wired.IWiredNode;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IComputerAccess;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheral;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheralProvider;
 | 
			
		||||
import dan200.computercraft.api.permissions.ITurtlePermissionProvider;
 | 
			
		||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
 | 
			
		||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
 | 
			
		||||
import net.minecraft.util.EnumFacing;
 | 
			
		||||
import net.minecraft.util.Direction;
 | 
			
		||||
import net.minecraft.util.math.BlockPos;
 | 
			
		||||
import net.minecraft.world.IBlockAccess;
 | 
			
		||||
import net.minecraft.world.IBlockReader;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
import net.minecraftforge.common.util.LazyOptional;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import java.lang.reflect.Method;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 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
 | 
			
		||||
{
 | 
			
		||||
    public static boolean isInstalled()
 | 
			
		||||
    {
 | 
			
		||||
        findCC();
 | 
			
		||||
        return computerCraft != null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static String getInstalledVersion()
 | 
			
		||||
    {
 | 
			
		||||
        findCC();
 | 
			
		||||
        if( computerCraft_getVersion != null )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                return (String) computerCraft_getVersion.invoke( null );
 | 
			
		||||
            }
 | 
			
		||||
            catch( Exception e )
 | 
			
		||||
            {
 | 
			
		||||
                // It failed
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return "";
 | 
			
		||||
        return getInstance().getInstalledVersion();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
@@ -82,19 +63,7 @@ public final class ComputerCraftAPI
 | 
			
		||||
     */
 | 
			
		||||
    public static int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
 | 
			
		||||
    {
 | 
			
		||||
        findCC();
 | 
			
		||||
        if( computerCraft_createUniqueNumberedSaveDir != null )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                return (Integer) computerCraft_createUniqueNumberedSaveDir.invoke( null, world, parentSubPath );
 | 
			
		||||
            }
 | 
			
		||||
            catch( Exception e )
 | 
			
		||||
            {
 | 
			
		||||
                // It failed
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return -1;
 | 
			
		||||
        return getInstance().createUniqueNumberedSaveDir( world, parentSubPath );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -118,78 +87,66 @@ public final class ComputerCraftAPI
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public static IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
 | 
			
		||||
    {
 | 
			
		||||
        findCC();
 | 
			
		||||
        if( computerCraft_createSaveDirMount != null )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                return (IWritableMount) computerCraft_createSaveDirMount.invoke( null, world, subPath, capacity );
 | 
			
		||||
            }
 | 
			
		||||
            catch( Exception e )
 | 
			
		||||
            {
 | 
			
		||||
                // It failed
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
        return getInstance().createSaveDirMount( world, subPath, capacity );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a file system mount to a resource folder, and returns it.
 | 
			
		||||
     *
 | 
			
		||||
     * Use in conjunction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a resource folder
 | 
			
		||||
     * 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 the specified mod jar, and resource packs that contain
 | 
			
		||||
     * The files in this mount will be a combination of files in all mod jar, and data packs that contain
 | 
			
		||||
     * resources with the same domain and path.
 | 
			
		||||
     *
 | 
			
		||||
     * @param modClass A class in whose jar to look first for the resources to mount. Using your main mod class is recommended. eg: MyMod.class
 | 
			
		||||
     * @param domain  The domain under which to look for resources. eg: "mymod".
 | 
			
		||||
     * @param subPath  The domain under which to look for resources. eg: "mymod/lua/myfiles".
 | 
			
		||||
     * @return The mount, or {@code null} if it could be created for some reason. Use IComputerAccess.mount() or
 | 
			
		||||
     * IComputerAccess.mountWritable() to mount this on a Computers' file system.
 | 
			
		||||
     * @param subPath The subPath under which to look for resources. eg: "lua/myfiles".
 | 
			
		||||
     * @return The mount, or {@code null} if it could be created for some reason.
 | 
			
		||||
     * @see IComputerAccess#mount(String, IMount)
 | 
			
		||||
     * @see IComputerAccess#mountWritable(String, IWritableMount)
 | 
			
		||||
     * @see IMount
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public static IMount createResourceMount( @Nonnull Class<?> modClass, @Nonnull String domain, @Nonnull String subPath )
 | 
			
		||||
    public static IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath )
 | 
			
		||||
    {
 | 
			
		||||
        findCC();
 | 
			
		||||
        if( computerCraft_createResourceMount != null )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                return (IMount) computerCraft_createResourceMount.invoke( null, modClass, domain, subPath );
 | 
			
		||||
        return getInstance().createResourceMount( domain, subPath );
 | 
			
		||||
    }
 | 
			
		||||
            catch( Exception e )
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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.
 | 
			
		||||
     *
 | 
			
		||||
     * 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.
 | 
			
		||||
     *
 | 
			
		||||
     * @param klass   The mod class to which the files belong.
 | 
			
		||||
     * @param domain  The domain under which to look for resources. eg: "mymod".
 | 
			
		||||
     * @param subPath The subPath under which to look for resources. eg: "lua/myfiles".
 | 
			
		||||
     * @return The mount, or {@code null} if it could be created for some reason.
 | 
			
		||||
     * @see IComputerAccess#mount(String, IMount)
 | 
			
		||||
     * @see IComputerAccess#mountWritable(String, IWritableMount)
 | 
			
		||||
     * @see IMount
 | 
			
		||||
     * @deprecated Use {@link #createResourceMount(String, String)} instead.
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static IMount createResourceMount( Class<?> klass, @Nonnull String domain, @Nonnull String subPath )
 | 
			
		||||
    {
 | 
			
		||||
                // It failed
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
        return getInstance().createResourceMount( domain, subPath );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Registers a peripheral provider to convert blocks into {@link IPeripheral} implementations.
 | 
			
		||||
     *
 | 
			
		||||
     * @param provider The peripheral provider to register.
 | 
			
		||||
     * @see dan200.computercraft.api.peripheral.IPeripheral
 | 
			
		||||
     * @see dan200.computercraft.api.peripheral.IPeripheralProvider
 | 
			
		||||
     * @see IPeripheral
 | 
			
		||||
     * @see IPeripheralProvider
 | 
			
		||||
     */
 | 
			
		||||
    public static void registerPeripheralProvider( @Nonnull IPeripheralProvider provider )
 | 
			
		||||
    {
 | 
			
		||||
        findCC();
 | 
			
		||||
        if( computerCraft_registerPeripheralProvider != null )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                computerCraft_registerPeripheralProvider.invoke( null, provider );
 | 
			
		||||
            }
 | 
			
		||||
            catch( Exception e )
 | 
			
		||||
            {
 | 
			
		||||
                // It failed
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        getInstance().registerPeripheralProvider( provider );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -198,47 +155,22 @@ public final class ComputerCraftAPI
 | 
			
		||||
     * this during the load() method of your mod.
 | 
			
		||||
     *
 | 
			
		||||
     * @param upgrade The turtle upgrade to register.
 | 
			
		||||
     * @see dan200.computercraft.api.turtle.ITurtleUpgrade
 | 
			
		||||
     * @see ITurtleUpgrade
 | 
			
		||||
     */
 | 
			
		||||
    public static void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade )
 | 
			
		||||
    {
 | 
			
		||||
        if( upgrade != null )
 | 
			
		||||
        {
 | 
			
		||||
            findCC();
 | 
			
		||||
            if( computerCraft_registerTurtleUpgrade != null )
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    computerCraft_registerTurtleUpgrade.invoke( null, upgrade );
 | 
			
		||||
                }
 | 
			
		||||
                catch( Exception e )
 | 
			
		||||
                {
 | 
			
		||||
                    // It failed
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        getInstance().registerTurtleUpgrade( upgrade );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Registers a bundled redstone provider to provide bundled redstone output for blocks.
 | 
			
		||||
     *
 | 
			
		||||
     * @param provider The bundled redstone provider to register.
 | 
			
		||||
     * @see dan200.computercraft.api.redstone.IBundledRedstoneProvider
 | 
			
		||||
     * @see IBundledRedstoneProvider
 | 
			
		||||
     */
 | 
			
		||||
    public static void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider )
 | 
			
		||||
    {
 | 
			
		||||
        findCC();
 | 
			
		||||
        if( computerCraft_registerBundledRedstoneProvider != null )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                computerCraft_registerBundledRedstoneProvider.invoke( null, provider );
 | 
			
		||||
            }
 | 
			
		||||
            catch( Exception e )
 | 
			
		||||
            {
 | 
			
		||||
                // It failed
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        getInstance().registerBundledRedstoneProvider( provider );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -249,85 +181,27 @@ public final class ComputerCraftAPI
 | 
			
		||||
     * @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.
 | 
			
		||||
     * @see dan200.computercraft.api.redstone.IBundledRedstoneProvider
 | 
			
		||||
     * @see IBundledRedstoneProvider
 | 
			
		||||
     */
 | 
			
		||||
    public static int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side )
 | 
			
		||||
    public static int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
 | 
			
		||||
    {
 | 
			
		||||
        findCC();
 | 
			
		||||
        if( computerCraft_getDefaultBundledRedstoneOutput != null )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                return (Integer) computerCraft_getDefaultBundledRedstoneOutput.invoke( null, world, pos, side );
 | 
			
		||||
            }
 | 
			
		||||
            catch( Exception e )
 | 
			
		||||
            {
 | 
			
		||||
                // It failed
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return -1;
 | 
			
		||||
        return getInstance().getBundledRedstoneOutput( world, pos, side );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Registers a media provider to provide {@link IMedia} implementations for Items
 | 
			
		||||
     * Registers a media provider to provide {@link IMedia} implementations for Items.
 | 
			
		||||
     *
 | 
			
		||||
     * @param provider The media provider to register.
 | 
			
		||||
     * @see dan200.computercraft.api.media.IMediaProvider
 | 
			
		||||
     * @see IMediaProvider
 | 
			
		||||
     */
 | 
			
		||||
    public static void registerMediaProvider( @Nonnull IMediaProvider provider )
 | 
			
		||||
    {
 | 
			
		||||
        findCC();
 | 
			
		||||
        if( computerCraft_registerMediaProvider != null )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                computerCraft_registerMediaProvider.invoke( null, provider );
 | 
			
		||||
            }
 | 
			
		||||
            catch( Exception e )
 | 
			
		||||
            {
 | 
			
		||||
                // It failed
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Registers a permission provider to restrict where turtles can move or build.
 | 
			
		||||
     *
 | 
			
		||||
     * @param provider The turtle permission provider to register.
 | 
			
		||||
     * @see dan200.computercraft.api.permissions.ITurtlePermissionProvider
 | 
			
		||||
     * @deprecated Prefer using {@link dan200.computercraft.api.turtle.event.TurtleBlockEvent} or the standard Forge events.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static void registerPermissionProvider( @Nonnull ITurtlePermissionProvider provider )
 | 
			
		||||
    {
 | 
			
		||||
        findCC();
 | 
			
		||||
        if( computerCraft_registerPermissionProvider != null )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                computerCraft_registerPermissionProvider.invoke( null, provider );
 | 
			
		||||
            }
 | 
			
		||||
            catch( Exception e )
 | 
			
		||||
            {
 | 
			
		||||
                // It failed
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        getInstance().registerMediaProvider( provider );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
 | 
			
		||||
    {
 | 
			
		||||
        findCC();
 | 
			
		||||
        if( computerCraft_registerPocketUpgrade != null )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                computerCraft_registerPocketUpgrade.invoke( null, upgrade );
 | 
			
		||||
            }
 | 
			
		||||
            catch( Exception e )
 | 
			
		||||
            {
 | 
			
		||||
                // It failed
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        getInstance().registerPocketUpgrade( upgrade );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -337,40 +211,16 @@ public final class ComputerCraftAPI
 | 
			
		||||
     */
 | 
			
		||||
    public static IPacketNetwork getWirelessNetwork()
 | 
			
		||||
    {
 | 
			
		||||
        findCC();
 | 
			
		||||
        if( computerCraft_getWirelessNetwork != null )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                return (IPacketNetwork) computerCraft_getWirelessNetwork.invoke( null );
 | 
			
		||||
            }
 | 
			
		||||
            catch( Exception e )
 | 
			
		||||
            {
 | 
			
		||||
                // It failed;
 | 
			
		||||
            }
 | 
			
		||||
        return getInstance().getWirelessNetwork();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void registerAPIFactory( @Nonnull ILuaAPIFactory upgrade )
 | 
			
		||||
    public static void registerAPIFactory( @Nonnull ILuaAPIFactory factory )
 | 
			
		||||
    {
 | 
			
		||||
        findCC();
 | 
			
		||||
        if( computerCraft_registerAPIFactory != null )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                computerCraft_registerAPIFactory.invoke( null, upgrade );
 | 
			
		||||
            }
 | 
			
		||||
            catch( Exception e )
 | 
			
		||||
            {
 | 
			
		||||
                // It failed
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        getInstance().registerAPIFactory( factory );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Construct a new wired node for a given wired element
 | 
			
		||||
     * Construct a new wired node for a given wired element.
 | 
			
		||||
     *
 | 
			
		||||
     * @param element The element to construct it for
 | 
			
		||||
     * @return The element's node
 | 
			
		||||
@@ -379,26 +229,11 @@ public final class ComputerCraftAPI
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element )
 | 
			
		||||
    {
 | 
			
		||||
        findCC();
 | 
			
		||||
        if( computerCraft_createWiredNodeForElement != null )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                return (IWiredNode) computerCraft_createWiredNodeForElement.invoke( null, element );
 | 
			
		||||
            }
 | 
			
		||||
            catch( ReflectiveOperationException e )
 | 
			
		||||
            {
 | 
			
		||||
                throw new IllegalStateException( "Error creating wired node", e );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            throw new IllegalStateException( "ComputerCraft cannot be found" );
 | 
			
		||||
        }
 | 
			
		||||
        return getInstance().createWiredNodeForElement( element );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the wired network element for a block in world
 | 
			
		||||
     * Get the wired network element for a block in world.
 | 
			
		||||
     *
 | 
			
		||||
     * @param world The world the block exists in
 | 
			
		||||
     * @param pos   The position the block exists in
 | 
			
		||||
@@ -406,118 +241,64 @@ public final class ComputerCraftAPI
 | 
			
		||||
     * @return The element's node
 | 
			
		||||
     * @see IWiredElement#getNode()
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader 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 );
 | 
			
		||||
 | 
			
		||||
        @Nullable
 | 
			
		||||
    public static IWiredElement getWiredElementAt( @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull EnumFacing side )
 | 
			
		||||
    {
 | 
			
		||||
        findCC();
 | 
			
		||||
        if( computerCraft_getWiredElementAt != null )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                return (IWiredElement) computerCraft_getWiredElementAt.invoke( null, world, pos, side );
 | 
			
		||||
            }
 | 
			
		||||
            catch( ReflectiveOperationException ignored )
 | 
			
		||||
            {
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity );
 | 
			
		||||
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
        @Nullable
 | 
			
		||||
        IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath );
 | 
			
		||||
 | 
			
		||||
    // The functions below here are private, and are used to interface with the non-API ComputerCraft classes.
 | 
			
		||||
    // Reflection is used here so you can develop your mod without decompiling ComputerCraft and including
 | 
			
		||||
    // it in your solution, and so your mod won't crash if ComputerCraft is installed.
 | 
			
		||||
        void registerPeripheralProvider( @Nonnull IPeripheralProvider provider );
 | 
			
		||||
 | 
			
		||||
    private static void findCC()
 | 
			
		||||
    {
 | 
			
		||||
        if( !ccSearched )
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                computerCraft = Class.forName( "dan200.computercraft.ComputerCraft" );
 | 
			
		||||
                computerCraft_getVersion = findCCMethod( "getVersion", new Class<?>[] {
 | 
			
		||||
                } );
 | 
			
		||||
                computerCraft_createUniqueNumberedSaveDir = findCCMethod( "createUniqueNumberedSaveDir", new Class<?>[] {
 | 
			
		||||
                    World.class, String.class
 | 
			
		||||
                } );
 | 
			
		||||
                computerCraft_createSaveDirMount = findCCMethod( "createSaveDirMount", new Class<?>[] {
 | 
			
		||||
                    World.class, String.class, Long.TYPE
 | 
			
		||||
                } );
 | 
			
		||||
                computerCraft_createResourceMount = findCCMethod( "createResourceMount", new Class<?>[] {
 | 
			
		||||
                    Class.class, String.class, String.class
 | 
			
		||||
                } );
 | 
			
		||||
                computerCraft_registerPeripheralProvider = findCCMethod( "registerPeripheralProvider", new Class<?>[] {
 | 
			
		||||
                    IPeripheralProvider.class
 | 
			
		||||
                } );
 | 
			
		||||
                computerCraft_registerTurtleUpgrade = findCCMethod( "registerTurtleUpgrade", new Class<?>[] {
 | 
			
		||||
                    ITurtleUpgrade.class
 | 
			
		||||
                } );
 | 
			
		||||
                computerCraft_registerBundledRedstoneProvider = findCCMethod( "registerBundledRedstoneProvider", new Class<?>[] {
 | 
			
		||||
                    IBundledRedstoneProvider.class
 | 
			
		||||
                } );
 | 
			
		||||
                computerCraft_getDefaultBundledRedstoneOutput = findCCMethod( "getDefaultBundledRedstoneOutput", new Class<?>[] {
 | 
			
		||||
                    World.class, BlockPos.class, EnumFacing.class
 | 
			
		||||
                } );
 | 
			
		||||
                computerCraft_registerMediaProvider = findCCMethod( "registerMediaProvider", new Class<?>[] {
 | 
			
		||||
                    IMediaProvider.class
 | 
			
		||||
                } );
 | 
			
		||||
                computerCraft_registerPermissionProvider = findCCMethod( "registerPermissionProvider", new Class<?>[] {
 | 
			
		||||
                    ITurtlePermissionProvider.class
 | 
			
		||||
                } );
 | 
			
		||||
                computerCraft_registerPocketUpgrade = findCCMethod( "registerPocketUpgrade", new Class<?>[] {
 | 
			
		||||
                    IPocketUpgrade.class
 | 
			
		||||
                } );
 | 
			
		||||
                computerCraft_getWirelessNetwork = findCCMethod( "getWirelessNetwork", new Class<?>[] {
 | 
			
		||||
                } );
 | 
			
		||||
                computerCraft_registerAPIFactory = findCCMethod( "registerAPIFactory", new Class<?>[] {
 | 
			
		||||
                    ILuaAPIFactory.class
 | 
			
		||||
                } );
 | 
			
		||||
                computerCraft_createWiredNodeForElement = findCCMethod( "createWiredNodeForElement", new Class<?>[] {
 | 
			
		||||
                    IWiredElement.class
 | 
			
		||||
                } );
 | 
			
		||||
                computerCraft_getWiredElementAt = findCCMethod( "getWiredElementAt", new Class<?>[] {
 | 
			
		||||
                    IBlockAccess.class, BlockPos.class, EnumFacing.class
 | 
			
		||||
                } );
 | 
			
		||||
            }
 | 
			
		||||
            catch( Exception e )
 | 
			
		||||
            {
 | 
			
		||||
                System.out.println( "ComputerCraftAPI: ComputerCraft not found." );
 | 
			
		||||
            }
 | 
			
		||||
            finally
 | 
			
		||||
            {
 | 
			
		||||
                ccSearched = true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
        void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade );
 | 
			
		||||
 | 
			
		||||
    private static Method findCCMethod( String name, Class<?>[] args )
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            return computerCraft != null ? computerCraft.getMethod( name, args ) : null;
 | 
			
		||||
        }
 | 
			
		||||
        catch( NoSuchMethodException e )
 | 
			
		||||
        {
 | 
			
		||||
            System.out.println( "ComputerCraftAPI: ComputerCraft method " + name + " not found." );
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
        void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider );
 | 
			
		||||
 | 
			
		||||
    private static boolean ccSearched = false;
 | 
			
		||||
    private static Class<?> computerCraft = null;
 | 
			
		||||
    private static Method computerCraft_getVersion = null;
 | 
			
		||||
    private static Method computerCraft_createUniqueNumberedSaveDir = null;
 | 
			
		||||
    private static Method computerCraft_createSaveDirMount = null;
 | 
			
		||||
    private static Method computerCraft_createResourceMount = null;
 | 
			
		||||
    private static Method computerCraft_registerPeripheralProvider = null;
 | 
			
		||||
    private static Method computerCraft_registerTurtleUpgrade = null;
 | 
			
		||||
    private static Method computerCraft_registerBundledRedstoneProvider = null;
 | 
			
		||||
    private static Method computerCraft_getDefaultBundledRedstoneOutput = null;
 | 
			
		||||
    private static Method computerCraft_registerMediaProvider = null;
 | 
			
		||||
    private static Method computerCraft_registerPermissionProvider = null;
 | 
			
		||||
    private static Method computerCraft_registerPocketUpgrade = null;
 | 
			
		||||
    private static Method computerCraft_getWirelessNetwork = null;
 | 
			
		||||
    private static Method computerCraft_registerAPIFactory = null;
 | 
			
		||||
    private static Method computerCraft_createWiredNodeForElement = null;
 | 
			
		||||
    private static Method computerCraft_getWiredElementAt = null;
 | 
			
		||||
        int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
 | 
			
		||||
 | 
			
		||||
        void registerMediaProvider( @Nonnull IMediaProvider provider );
 | 
			
		||||
 | 
			
		||||
        void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade );
 | 
			
		||||
 | 
			
		||||
        @Nonnull
 | 
			
		||||
        IPacketNetwork getWirelessNetwork();
 | 
			
		||||
 | 
			
		||||
        void registerAPIFactory( @Nonnull ILuaAPIFactory factory );
 | 
			
		||||
 | 
			
		||||
        @Nonnull
 | 
			
		||||
        IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element );
 | 
			
		||||
 | 
			
		||||
        @Nonnull
 | 
			
		||||
        LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction side );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,41 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
package dan200.computercraft.api.filesystem;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * An {@link IOException} which occurred on a specific file.
 | 
			
		||||
 *
 | 
			
		||||
 * This may be thrown from a {@link IMount} or {@link IWritableMount} to give more information about a failure.
 | 
			
		||||
 */
 | 
			
		||||
public class FileOperationException extends IOException
 | 
			
		||||
{
 | 
			
		||||
    private static final long serialVersionUID = -8809108200853029849L;
 | 
			
		||||
 | 
			
		||||
    private final String filename;
 | 
			
		||||
 | 
			
		||||
    public FileOperationException( @Nullable String filename, @Nonnull String message )
 | 
			
		||||
    {
 | 
			
		||||
        super( Objects.requireNonNull( message, "message cannot be null" ) );
 | 
			
		||||
        this.filename = filename;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public FileOperationException( String message )
 | 
			
		||||
    {
 | 
			
		||||
        super( Objects.requireNonNull( message, "message cannot be null" ) );
 | 
			
		||||
        this.filename = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public String getFilename()
 | 
			
		||||
    {
 | 
			
		||||
        return filename;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
@@ -19,7 +18,7 @@ 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)}
 | 
			
		||||
 * {@link IComputerAccess#mount(String, IMount)}.
 | 
			
		||||
 *
 | 
			
		||||
 * Ready made implementations of this interface can be created using
 | 
			
		||||
 * {@link ComputerCraftAPI#createSaveDirMount(World, String, long)} or
 | 
			
		||||
@@ -60,7 +59,7 @@ public interface IMount
 | 
			
		||||
    void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the size of a file with a given path, in bytes
 | 
			
		||||
     * Returns the size of a file with a given path, in bytes.
 | 
			
		||||
     *
 | 
			
		||||
     * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
 | 
			
		||||
     * @return The size of the file, in bytes.
 | 
			
		||||
@@ -90,7 +89,6 @@ public interface IMount
 | 
			
		||||
     * @throws IOException If the file does not exist, or could not be opened.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @SuppressWarnings( "deprecation" )
 | 
			
		||||
    default ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        return Channels.newChannel( openForRead( path ) );
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
@@ -67,7 +66,6 @@ public interface IWritableMount extends IMount
 | 
			
		||||
     * @throws IOException If the file could not be opened for writing.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @SuppressWarnings( "deprecation" )
 | 
			
		||||
    default WritableByteChannel openChannelForWrite( @Nonnull String path ) throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        return Channels.newChannel( openForWrite( path ) );
 | 
			
		||||
@@ -94,7 +92,6 @@ public interface IWritableMount extends IMount
 | 
			
		||||
     * @throws IOException If the file could not be opened for writing.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @SuppressWarnings( "deprecation" )
 | 
			
		||||
    default WritableByteChannel openChannelForAppend( @Nonnull String path ) throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        return Channels.newChannel( openForAppend( path ) );
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|FileSystem", apiVersion = "${version}" )
 | 
			
		||||
package dan200.computercraft.api.filesystem;
 | 
			
		||||
 | 
			
		||||
import net.minecraftforge.fml.common.API;
 | 
			
		||||
							
								
								
									
										334
									
								
								src/main/java/dan200/computercraft/api/lua/ArgumentHelper.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										334
									
								
								src/main/java/dan200/computercraft/api/lua/ArgumentHelper.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,334 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.peripheral.IComputerAccess;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheral;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Provides methods for extracting values and validating Lua arguments, such as those provided to
 | 
			
		||||
 * {@link ILuaObject#callMethod(ILuaContext, int, Object[])} or
 | 
			
		||||
 * {@link IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])}.
 | 
			
		||||
 *
 | 
			
		||||
 * This provides two sets of functions: the {@code get*} methods, which require an argument to be valid, and
 | 
			
		||||
 * {@code opt*}, which accept a default value and return that if the argument was not present or was {@code null}.
 | 
			
		||||
 * If the argument is of the wrong type, a suitable error message will be thrown, with a similar format to Lua's own
 | 
			
		||||
 * error messages.
 | 
			
		||||
 *
 | 
			
		||||
 * <h2>Example usage:</h2>
 | 
			
		||||
 * <pre>
 | 
			
		||||
 * {@code
 | 
			
		||||
 * int slot = getInt( args, 0 );
 | 
			
		||||
 * int amount = optInt( args, 1, 64 );
 | 
			
		||||
 * }
 | 
			
		||||
 * </pre>
 | 
			
		||||
 */
 | 
			
		||||
public final class ArgumentHelper
 | 
			
		||||
{
 | 
			
		||||
    private ArgumentHelper()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a string representation of the given value's type.
 | 
			
		||||
     *
 | 
			
		||||
     * @param value The value whose type we are trying to compute.
 | 
			
		||||
     * @return A string representation of the given value's type, in a similar format to that provided by Lua's
 | 
			
		||||
     * {@code type} function.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static String getType( @Nullable Object value )
 | 
			
		||||
    {
 | 
			
		||||
        if( value == null ) return "nil";
 | 
			
		||||
        if( value instanceof String ) return "string";
 | 
			
		||||
        if( value instanceof Boolean ) return "boolean";
 | 
			
		||||
        if( value instanceof Number ) return "number";
 | 
			
		||||
        if( value instanceof Map ) return "table";
 | 
			
		||||
        return "userdata";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Construct a "bad argument" exception, from an expected type and the actual value provided.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index    The argument number, starting from 0.
 | 
			
		||||
     * @param expected The expected type for this argument.
 | 
			
		||||
     * @param actual   The actual value provided for this argument.
 | 
			
		||||
     * @return The constructed exception, which should be thrown immediately.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static LuaException badArgumentOf( int index, @Nonnull String expected, @Nullable Object actual )
 | 
			
		||||
    {
 | 
			
		||||
        return badArgument( index, expected, getType( actual ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Construct a "bad argument" exception, from an expected and actual type.
 | 
			
		||||
     *
 | 
			
		||||
     * @param index    The argument number, starting from 0.
 | 
			
		||||
     * @param expected The expected type for this argument.
 | 
			
		||||
     * @param actual   The provided type for this argument.
 | 
			
		||||
     * @return The constructed exception, which should be thrown immediately.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static LuaException badArgument( int index, @Nonnull String expected, @Nonnull String actual )
 | 
			
		||||
    {
 | 
			
		||||
        return new LuaException( "bad argument #" + (index + 1) + " (" + expected + " expected, got " + actual + ")" );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a double.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not a number.
 | 
			
		||||
     * @see #getFiniteDouble(Object[], int) if you require this to be finite (i.e. not infinite or NaN).
 | 
			
		||||
     */
 | 
			
		||||
    public static double getDouble( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( index >= args.length ) throw badArgument( index, "number", "nil" );
 | 
			
		||||
        Object value = args[index];
 | 
			
		||||
        if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
 | 
			
		||||
        return ((Number) value).doubleValue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as an integer.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not an integer.
 | 
			
		||||
     */
 | 
			
		||||
    public static int getInt( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return (int) getLong( args, index );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a long.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not a long.
 | 
			
		||||
     */
 | 
			
		||||
    public static long getLong( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( index >= args.length ) throw badArgument( index, "number", "nil" );
 | 
			
		||||
        Object value = args[index];
 | 
			
		||||
        if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
 | 
			
		||||
        return checkFinite( index, (Number) value ).longValue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a finite number (not infinite or NaN).
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not finite.
 | 
			
		||||
     */
 | 
			
		||||
    public static double getFiniteDouble( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return checkFinite( index, getDouble( args, index ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a boolean.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not a boolean.
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean getBoolean( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( index >= args.length ) throw badArgument( index, "boolean", "nil" );
 | 
			
		||||
        Object value = args[index];
 | 
			
		||||
        if( !(value instanceof Boolean) ) throw badArgumentOf( index, "boolean", value );
 | 
			
		||||
        return (Boolean) value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a string.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not a string.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static String getString( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( index >= args.length ) throw badArgument( index, "string", "nil" );
 | 
			
		||||
        Object value = args[index];
 | 
			
		||||
        if( !(value instanceof String) ) throw badArgumentOf( index, "string", value );
 | 
			
		||||
        return (String) value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a table.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @return The argument's value.
 | 
			
		||||
     * @throws LuaException If the value is not a table.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static Map<?, ?> getTable( @Nonnull Object[] args, int index ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( index >= args.length ) throw badArgument( index, "table", "nil" );
 | 
			
		||||
        Object value = args[index];
 | 
			
		||||
        if( !(value instanceof Map) ) throw badArgumentOf( index, "table", value );
 | 
			
		||||
        return (Map<?, ?>) value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a double.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @param def   The default value, if this argument is not given.
 | 
			
		||||
     * @return The argument's value, or {@code def} if none was provided.
 | 
			
		||||
     * @throws LuaException If the value is not a number.
 | 
			
		||||
     */
 | 
			
		||||
    public static double optDouble( @Nonnull Object[] args, int index, double def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = index < args.length ? args[index] : null;
 | 
			
		||||
        if( value == null ) return def;
 | 
			
		||||
        if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
 | 
			
		||||
        return ((Number) value).doubleValue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as an int.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @param def   The default value, if this argument is not given.
 | 
			
		||||
     * @return The argument's value, or {@code def} if none was provided.
 | 
			
		||||
     * @throws LuaException If the value is not a number.
 | 
			
		||||
     */
 | 
			
		||||
    public static int optInt( @Nonnull Object[] args, int index, int def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return (int) optLong( args, index, def );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a long.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @param def   The default value, if this argument is not given.
 | 
			
		||||
     * @return The argument's value, or {@code def} if none was provided.
 | 
			
		||||
     * @throws LuaException If the value is not a number.
 | 
			
		||||
     */
 | 
			
		||||
    public static long optLong( @Nonnull Object[] args, int index, long def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = index < args.length ? args[index] : null;
 | 
			
		||||
        if( value == null ) return def;
 | 
			
		||||
        if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
 | 
			
		||||
        return checkFinite( index, (Number) value ).longValue();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a finite number (not infinite or NaN).
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @param def   The default value, if this argument is not given.
 | 
			
		||||
     * @return The argument's value, or {@code def} if none was provided.
 | 
			
		||||
     * @throws LuaException If the value is not finite.
 | 
			
		||||
     */
 | 
			
		||||
    public static double optFiniteDouble( @Nonnull Object[] args, int index, double def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        return checkFinite( index, optDouble( args, index, def ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a boolean.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @param def   The default value, if this argument is not given.
 | 
			
		||||
     * @return The argument's value, or {@code def} if none was provided.
 | 
			
		||||
     * @throws LuaException If the value is not a boolean.
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean optBoolean( @Nonnull Object[] args, int index, boolean def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = index < args.length ? args[index] : null;
 | 
			
		||||
        if( value == null ) return def;
 | 
			
		||||
        if( !(value instanceof Boolean) ) throw badArgumentOf( index, "boolean", value );
 | 
			
		||||
        return (Boolean) value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a string.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @param def   The default value, if this argument is not given.
 | 
			
		||||
     * @return The argument's value, or {@code def} if none was provided.
 | 
			
		||||
     * @throws LuaException If the value is not a string.
 | 
			
		||||
     */
 | 
			
		||||
    public static String optString( @Nonnull Object[] args, int index, String def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = index < args.length ? args[index] : null;
 | 
			
		||||
        if( value == null ) return def;
 | 
			
		||||
        if( !(value instanceof String) ) throw badArgumentOf( index, "string", value );
 | 
			
		||||
        return (String) value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get an argument as a table.
 | 
			
		||||
     *
 | 
			
		||||
     * @param args  The arguments to extract from.
 | 
			
		||||
     * @param index The index into the argument array to read from.
 | 
			
		||||
     * @param def   The default value, if this argument is not given.
 | 
			
		||||
     * @return The argument's value, or {@code def} if none was provided.
 | 
			
		||||
     * @throws LuaException If the value is not a table.
 | 
			
		||||
     */
 | 
			
		||||
    public static Map<?, ?> optTable( @Nonnull Object[] args, int index, Map<Object, Object> def ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        Object value = index < args.length ? args[index] : null;
 | 
			
		||||
        if( value == null ) return def;
 | 
			
		||||
        if( !(value instanceof Map) ) throw badArgumentOf( index, "table", value );
 | 
			
		||||
        return (Map<?, ?>) value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static Number checkFinite( int index, Number value ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        checkFinite( index, value.doubleValue() );
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static double checkFinite( int index, double value ) throws LuaException
 | 
			
		||||
    {
 | 
			
		||||
        if( !Double.isFinite( value ) ) throw badArgument( index, "number", getNumericType( value ) );
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns a more detailed representation of this number's type. If this is finite, it will just return "number",
 | 
			
		||||
     * otherwise it returns whether it is infinite or NaN.
 | 
			
		||||
     *
 | 
			
		||||
     * @param value The value to extract the type for.
 | 
			
		||||
     * @return This value's numeric type.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public static String getNumericType( double value )
 | 
			
		||||
    {
 | 
			
		||||
        if( Double.isNaN( value ) ) return "nan";
 | 
			
		||||
        if( value == Double.POSITIVE_INFINITY ) return "inf";
 | 
			
		||||
        if( value == Double.NEGATIVE_INFINITY ) return "-inf";
 | 
			
		||||
        return "number";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
@@ -26,7 +25,7 @@ public interface IComputerSystem extends IComputerAccess
 | 
			
		||||
    IFileSystem getFileSystem();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the label for this computer
 | 
			
		||||
     * Get the label for this computer.
 | 
			
		||||
     *
 | 
			
		||||
     * @return This computer's label, or {@code null} if it is not set.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
@@ -17,6 +16,7 @@ import javax.annotation.Nullable;
 | 
			
		||||
 * @see ILuaAPI
 | 
			
		||||
 * @see ComputerCraftAPI#registerAPIFactory(ILuaAPIFactory)
 | 
			
		||||
 */
 | 
			
		||||
@FunctionalInterface
 | 
			
		||||
public interface ILuaAPIFactory
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
@@ -32,7 +31,12 @@ public interface ILuaContext
 | 
			
		||||
     *                              intercepted, or the computer will leak memory and end up in a broken state.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    Object[] pullEvent( @Nullable String filter ) throws LuaException, InterruptedException;
 | 
			
		||||
    default Object[] pullEvent( @Nullable String filter ) throws LuaException, InterruptedException
 | 
			
		||||
    {
 | 
			
		||||
        Object[] results = pullEventRaw( filter );
 | 
			
		||||
        if( results.length >= 1 && results[0].equals( "terminate" ) ) throw new LuaException( "Terminated", 0 );
 | 
			
		||||
        return results;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The same as {@link #pullEvent(String)}, except "terminated" events are ignored. Only use this if you want to
 | 
			
		||||
@@ -47,7 +51,10 @@ public interface ILuaContext
 | 
			
		||||
     * @see #pullEvent(String)
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    Object[] pullEventRaw( @Nullable String filter ) throws InterruptedException;
 | 
			
		||||
    default Object[] pullEventRaw( @Nullable String filter ) throws InterruptedException
 | 
			
		||||
    {
 | 
			
		||||
        return yield( new Object[] { filter } );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Lua", apiVersion = "${version}" )
 | 
			
		||||
package dan200.computercraft.api.lua;
 | 
			
		||||
 | 
			
		||||
import net.minecraftforge.fml.common.API;
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.util.SoundEvent;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
@@ -16,7 +16,9 @@ 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 Item class to allow it to be used in the drive.
 | 
			
		||||
 *
 | 
			
		||||
 * 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
 | 
			
		||||
{
 | 
			
		||||
@@ -43,7 +45,7 @@ public interface IMedia
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * If this disk represents an item with audio (like a record), get the readable name of the audio track. ie:
 | 
			
		||||
     * "Jonathon Coulton - Still Alive"
 | 
			
		||||
     * "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.
 | 
			
		||||
@@ -74,7 +76,7 @@ public interface IMedia
 | 
			
		||||
     * @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()
 | 
			
		||||
     * @see dan200.computercraft.api.filesystem.IMount
 | 
			
		||||
     * @see IMount
 | 
			
		||||
     * @see dan200.computercraft.api.filesystem.IWritableMount
 | 
			
		||||
     * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String, long)
 | 
			
		||||
     * @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
@@ -23,7 +22,7 @@ public interface IMediaProvider
 | 
			
		||||
     * Produce an IMedia implementation from an ItemStack.
 | 
			
		||||
     *
 | 
			
		||||
     * @param stack The stack from which to extract the media information.
 | 
			
		||||
     * @return An IMedia implementation, or null if the item is not something you wish to handle
 | 
			
		||||
     * @return An {@link IMedia} implementation, or {@code null} if the item is not something you wish to handle
 | 
			
		||||
     * @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider)
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Media", apiVersion = "${version}" )
 | 
			
		||||
package dan200.computercraft.api.media;
 | 
			
		||||
 | 
			
		||||
import net.minecraftforge.fml.common.API;
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Network", apiVersion = "${version}" )
 | 
			
		||||
package dan200.computercraft.api.network;
 | 
			
		||||
 | 
			
		||||
import net.minecraftforge.fml.common.API;
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Network|Wired", apiVersion = "${version}" )
 | 
			
		||||
package dan200.computercraft.api.network.wired;
 | 
			
		||||
 | 
			
		||||
import net.minecraftforge.fml.common.API;
 | 
			
		||||
@@ -1,10 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API", apiVersion = "${version}" )
 | 
			
		||||
package dan200.computercraft.api;
 | 
			
		||||
 | 
			
		||||
import net.minecraftforge.fml.common.API;
 | 
			
		||||
@@ -1,14 +1,15 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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;
 | 
			
		||||
import dan200.computercraft.api.filesystem.IMount;
 | 
			
		||||
import dan200.computercraft.api.filesystem.IWritableMount;
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaContext;
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaTask;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
@@ -146,7 +147,7 @@ public interface IComputerAccess
 | 
			
		||||
     *
 | 
			
		||||
     *                  You may supply {@code null} to indicate that no arguments are to be supplied.
 | 
			
		||||
     * @throws RuntimeException If the peripheral has been detached.
 | 
			
		||||
     * @see dan200.computercraft.api.peripheral.IPeripheral#callMethod
 | 
			
		||||
     * @see IPeripheral#callMethod
 | 
			
		||||
     */
 | 
			
		||||
    void queueEvent( @Nonnull String event, @Nullable Object[] arguments );
 | 
			
		||||
 | 
			
		||||
@@ -179,8 +180,8 @@ public interface IComputerAccess
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get a reachable peripheral with the given attachement name. This is a equivalent to
 | 
			
		||||
     * {@link #getAvailablePeripherals()}{@code .get(name)}, though may be more performant.
 | 
			
		||||
     * 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.
 | 
			
		||||
@@ -191,4 +192,23 @@ public interface IComputerAccess
 | 
			
		||||
    {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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.
 | 
			
		||||
     *
 | 
			
		||||
     * 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.
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    default IWorkMonitor getMainThreadMonitor()
 | 
			
		||||
    {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,11 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.ArgumentHelper;
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaContext;
 | 
			
		||||
import dan200.computercraft.api.lua.LuaException;
 | 
			
		||||
 | 
			
		||||
@@ -41,8 +41,8 @@ public interface IPeripheral
 | 
			
		||||
     * This is called when a lua program on an attached computer calls {@code peripheral.call()} with
 | 
			
		||||
     * one of the methods exposed by {@link #getMethodNames()}.
 | 
			
		||||
     *
 | 
			
		||||
     * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe
 | 
			
		||||
     * when interacting with Minecraft objects.
 | 
			
		||||
     * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe when interacting
 | 
			
		||||
     * with Minecraft objects.
 | 
			
		||||
     *
 | 
			
		||||
     * @param computer  The interface to the computer that is making the call. Remember that multiple
 | 
			
		||||
     *                  computers can be attached to a peripheral at once.
 | 
			
		||||
@@ -58,9 +58,11 @@ public interface IPeripheral
 | 
			
		||||
     *                  Lua values of type "table" will be represented by Object type Map.<br>
 | 
			
		||||
     *                  Lua values of any other type will be represented by a null object.<br>
 | 
			
		||||
     *                  This array will be empty if no arguments are passed.
 | 
			
		||||
     *
 | 
			
		||||
     *                  It is recommended you use {@link ArgumentHelper} in order to validate and process arguments.
 | 
			
		||||
     * @return An array of objects, representing values you wish to return to the lua program. Integers, Doubles, Floats,
 | 
			
		||||
     * Strings, Booleans, Maps and ILuaObject and null be converted to their corresponding lua type. All other types
 | 
			
		||||
     * will be converted to nil.
 | 
			
		||||
     * Strings, Booleans, Maps, ILuaObject and null be converted to their corresponding lua type. All other types will
 | 
			
		||||
     * be converted to nil.
 | 
			
		||||
     *
 | 
			
		||||
     * You may return null to indicate no values should be returned.
 | 
			
		||||
     * @throws LuaException         If you throw any exception from this function, a lua error will be raised with the
 | 
			
		||||
@@ -70,25 +72,27 @@ public interface IPeripheral
 | 
			
		||||
     *                              InterruptedException will be thrown. This exception must not be caught or
 | 
			
		||||
     *                              intercepted, or the computer will leak memory and end up in a broken state.
 | 
			
		||||
     * @see #getMethodNames
 | 
			
		||||
     * @see ArgumentHelper
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Is called when canAttachToSide has returned true, and a computer is attaching to the peripheral.
 | 
			
		||||
     * Is called when when a computer is attaching to the peripheral.
 | 
			
		||||
     *
 | 
			
		||||
     * This will occur when a peripheral is placed next to an active computer, when a computer is turned on next to a
 | 
			
		||||
     * peripheral, or when a turtle travels into a square next to a peripheral.
 | 
			
		||||
     * peripheral, when a turtle travels into a square next to a peripheral, or when a wired modem adjacent to this
 | 
			
		||||
     * peripheral is does any of the above.
 | 
			
		||||
     *
 | 
			
		||||
     * Between calls to attach() and detach(), the attached computer can make method calls on the peripheral using
 | 
			
		||||
     * Between calls to attach and {@link #detach}, the attached computer can make method calls on the peripheral using
 | 
			
		||||
     * {@code peripheral.call()}. This method can be used to keep track of which computers are attached to the
 | 
			
		||||
     * peripheral, or to take action when attachment occurs.
 | 
			
		||||
     *
 | 
			
		||||
     * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe
 | 
			
		||||
     * when interacting with Minecraft objects.
 | 
			
		||||
     * Be aware that will be called from both the server thread and ComputerCraft Lua thread, and so must be thread-safe
 | 
			
		||||
     * and reentrant.
 | 
			
		||||
     *
 | 
			
		||||
     * @param computer The interface to the computer that is being attached. Remember that multiple
 | 
			
		||||
     *                 computers can be attached to a peripheral at once.
 | 
			
		||||
     * @param computer The interface to the computer that is being attached. Remember that multiple computers can be
 | 
			
		||||
     *                 attached to a peripheral at once.
 | 
			
		||||
     * @see #detach
 | 
			
		||||
     */
 | 
			
		||||
    default void attach( @Nonnull IComputerAccess computer )
 | 
			
		||||
@@ -96,19 +100,21 @@ public interface IPeripheral
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Is called when a computer is detaching from the peripheral.
 | 
			
		||||
     * Called when a computer is detaching from the peripheral.
 | 
			
		||||
     *
 | 
			
		||||
     * This will occur when a computer shuts down, when the peripheral is removed while attached to computers,
 | 
			
		||||
     * or when a turtle moves away from a square attached to a peripheral. This method can be used to keep track of
 | 
			
		||||
     * which computers are attached to the peripheral, or to take action when detachment
 | 
			
		||||
     * occurs.
 | 
			
		||||
     * This will occur when a computer shuts down, when the peripheral is removed while attached to computers, when a
 | 
			
		||||
     * turtle moves away from a block attached to a peripheral, or when a wired modem adjacent to this peripheral is
 | 
			
		||||
     * detached.
 | 
			
		||||
     *
 | 
			
		||||
     * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe
 | 
			
		||||
     * when interacting with Minecraft objects.
 | 
			
		||||
     * This method can be used to keep track of which computers are attached to the peripheral, or to take action when
 | 
			
		||||
     * detachment occurs.
 | 
			
		||||
     *
 | 
			
		||||
     * @param computer The interface to the computer that is being detached. Remember that multiple
 | 
			
		||||
     *                 computers can be attached to a peripheral at once.
 | 
			
		||||
     * @see #detach
 | 
			
		||||
     * Be aware that this will be called from both the server and ComputerCraft Lua thread, and must be thread-safe
 | 
			
		||||
     * and reentrant.
 | 
			
		||||
     *
 | 
			
		||||
     * @param computer The interface to the computer that is being detached. Remember that multiple computers can be
 | 
			
		||||
     *                 attached to a peripheral at once.
 | 
			
		||||
     * @see #attach
 | 
			
		||||
     */
 | 
			
		||||
    default void detach( @Nonnull IComputerAccess computer )
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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 net.minecraft.util.EnumFacing;
 | 
			
		||||
import net.minecraft.tileentity.TileEntity;
 | 
			
		||||
import net.minecraft.util.Direction;
 | 
			
		||||
import net.minecraft.util.math.BlockPos;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
 | 
			
		||||
@@ -16,6 +16,8 @@ import javax.annotation.Nullable;
 | 
			
		||||
/**
 | 
			
		||||
 * This interface is used to create peripheral implementations for blocks.
 | 
			
		||||
 *
 | 
			
		||||
 * If you have a {@link TileEntity} which acts as a peripheral, you may alternatively implement {@link IPeripheralTile}.
 | 
			
		||||
 *
 | 
			
		||||
 * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
 | 
			
		||||
 */
 | 
			
		||||
@FunctionalInterface
 | 
			
		||||
@@ -31,5 +33,5 @@ public interface IPeripheralProvider
 | 
			
		||||
     * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side );
 | 
			
		||||
    IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,32 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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 net.minecraft.util.Direction;
 | 
			
		||||
import net.minecraft.util.math.BlockPos;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A {@link net.minecraft.tileentity.TileEntity} which may act as a peripheral.
 | 
			
		||||
 *
 | 
			
		||||
 * If you need more complex capabilities (such as handling TEs not belonging to your mod), you should use
 | 
			
		||||
 * {@link IPeripheralProvider}.
 | 
			
		||||
 */
 | 
			
		||||
public interface IPeripheralTile
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the peripheral on the given {@code side}.
 | 
			
		||||
     *
 | 
			
		||||
     * @param side The side to get the peripheral from.
 | 
			
		||||
     * @return A peripheral, or {@code null} if there is not a peripheral here.
 | 
			
		||||
     * @see IPeripheralProvider#getPeripheral(World, BlockPos, Direction)
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    IPeripheral getPeripheral( @Nonnull Direction side );
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,77 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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 javax.annotation.Nonnull;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Monitors "work" associated with a computer, keeping track of how much a computer has done, and ensuring every
 | 
			
		||||
 * computer receives a fair share of any processing time.
 | 
			
		||||
 *
 | 
			
		||||
 * This is primarily intended for work done by peripherals on the main thread (such as on a tile entity's tick), but
 | 
			
		||||
 * could be used for other purposes (such as complex computations done on another thread).
 | 
			
		||||
 *
 | 
			
		||||
 * Before running a task, one should call {@link #canWork()} to determine if the computer is currently allowed to
 | 
			
		||||
 * execute work. If that returns true, you should execute the task and use {@link #trackWork(long, TimeUnit)} to inform
 | 
			
		||||
 * the monitor how long that task took.
 | 
			
		||||
 *
 | 
			
		||||
 * Alternatively, use {@link #runWork(Runnable)} to run and keep track of work.
 | 
			
		||||
 *
 | 
			
		||||
 * @see IComputerAccess#getMainThreadMonitor()
 | 
			
		||||
 */
 | 
			
		||||
public interface IWorkMonitor
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * If the owning computer is currently allowed to execute work.
 | 
			
		||||
     *
 | 
			
		||||
     * @return If we can execute work right now.
 | 
			
		||||
     */
 | 
			
		||||
    boolean canWork();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * If the owning computer is currently allowed to execute work, and has ample time to do so.
 | 
			
		||||
     *
 | 
			
		||||
     * This is effectively a more restrictive form of {@link #canWork()}. One should use that in order to determine if
 | 
			
		||||
     * you may do an initial piece of work, and shouldWork to determine if any additional task may be performed.
 | 
			
		||||
     *
 | 
			
		||||
     * @return If we should execute work right now.
 | 
			
		||||
     */
 | 
			
		||||
    boolean shouldWork();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Inform the monitor how long some piece of work took to execute.
 | 
			
		||||
     *
 | 
			
		||||
     * @param time The time some task took to run
 | 
			
		||||
     * @param unit The unit that {@code time} was measured in.
 | 
			
		||||
     */
 | 
			
		||||
    void trackWork( long time, @Nonnull TimeUnit unit );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Run a task if possible, and inform the monitor of how long it took.
 | 
			
		||||
     *
 | 
			
		||||
     * @param runnable The task to run.
 | 
			
		||||
     * @return If the task was actually run (namely, {@link #canWork()} returned {@code true}).
 | 
			
		||||
     */
 | 
			
		||||
    default boolean runWork( @Nonnull Runnable runnable )
 | 
			
		||||
    {
 | 
			
		||||
        Objects.requireNonNull( runnable, "runnable should not be null" );
 | 
			
		||||
        if( !canWork() ) return false;
 | 
			
		||||
 | 
			
		||||
        long start = System.nanoTime();
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            runnable.run();
 | 
			
		||||
        }
 | 
			
		||||
        finally
 | 
			
		||||
        {
 | 
			
		||||
            trackWork( System.nanoTime() - start, TimeUnit.NANOSECONDS );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,10 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Peripheral", apiVersion = "${version}" )
 | 
			
		||||
package dan200.computercraft.api.peripheral;
 | 
			
		||||
 | 
			
		||||
import net.minecraftforge.fml.common.API;
 | 
			
		||||
@@ -1,42 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.api.permissions;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.util.math.BlockPos;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This interface is used to restrict where turtles can move or build.
 | 
			
		||||
 *
 | 
			
		||||
 * Turtles will call these methods before attempting to perform an action, allowing them to be cancelled.
 | 
			
		||||
 *
 | 
			
		||||
 * @see dan200.computercraft.api.ComputerCraftAPI#registerPermissionProvider(ITurtlePermissionProvider)
 | 
			
		||||
 */
 | 
			
		||||
public interface ITurtlePermissionProvider
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine whether a block can be entered by a turtle.
 | 
			
		||||
     *
 | 
			
		||||
     * @param world The world the block exists in
 | 
			
		||||
     * @param pos   The location of the block.
 | 
			
		||||
     * @return Whether the turtle can move into this block.
 | 
			
		||||
     */
 | 
			
		||||
    boolean isBlockEnterable( @Nonnull World world, @Nonnull BlockPos pos );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine whether a block can be modified by a turtle.
 | 
			
		||||
     *
 | 
			
		||||
     * This includes breaking and placing blocks.
 | 
			
		||||
     *
 | 
			
		||||
     * @param world The world the block exists in
 | 
			
		||||
     * @param pos   The location of the block.
 | 
			
		||||
     * @return Whether the turtle can modify this block.
 | 
			
		||||
     */
 | 
			
		||||
    boolean isBlockEditable( @Nonnull World world, @Nonnull BlockPos pos );
 | 
			
		||||
}
 | 
			
		||||
@@ -1,10 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Permissions", apiVersion = "${version}" )
 | 
			
		||||
package dan200.computercraft.api.permissions;
 | 
			
		||||
 | 
			
		||||
import net.minecraftforge.fml.common.API;
 | 
			
		||||
@@ -0,0 +1,63 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.pocket;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraft.util.IItemProvider;
 | 
			
		||||
import net.minecraft.util.ResourceLocation;
 | 
			
		||||
import net.minecraft.util.Util;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A base class for {@link IPocketUpgrade}s.
 | 
			
		||||
 *
 | 
			
		||||
 * One does not have to use this, but it does provide a convenient template.
 | 
			
		||||
 */
 | 
			
		||||
public abstract class AbstractPocketUpgrade implements IPocketUpgrade
 | 
			
		||||
{
 | 
			
		||||
    private final ResourceLocation id;
 | 
			
		||||
    private final String adjective;
 | 
			
		||||
    private final ItemStack stack;
 | 
			
		||||
 | 
			
		||||
    protected AbstractPocketUpgrade( ResourceLocation id, String adjective, ItemStack stack )
 | 
			
		||||
    {
 | 
			
		||||
        this.id = id;
 | 
			
		||||
        this.adjective = adjective;
 | 
			
		||||
        this.stack = stack;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected AbstractPocketUpgrade( ResourceLocation id, String adjective, IItemProvider item )
 | 
			
		||||
    {
 | 
			
		||||
        this( id, adjective, new ItemStack( item ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected AbstractPocketUpgrade( ResourceLocation id, IItemProvider item )
 | 
			
		||||
    {
 | 
			
		||||
        this( id, Util.makeTranslationKey( "upgrade", id ) + ".adjective", new ItemStack( item ) );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @Override
 | 
			
		||||
    public final ResourceLocation getUpgradeID()
 | 
			
		||||
    {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @Override
 | 
			
		||||
    public final String getUnlocalisedAdjective()
 | 
			
		||||
    {
 | 
			
		||||
        return adjective;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @Override
 | 
			
		||||
    public final ItemStack getCraftingItem()
 | 
			
		||||
    {
 | 
			
		||||
        return stack;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,14 +1,13 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.pocket;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheral;
 | 
			
		||||
import net.minecraft.entity.Entity;
 | 
			
		||||
import net.minecraft.nbt.NBTTagCompound;
 | 
			
		||||
import net.minecraft.nbt.CompoundNBT;
 | 
			
		||||
import net.minecraft.util.ResourceLocation;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
@@ -16,14 +15,16 @@ import javax.annotation.Nullable;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Wrapper class for pocket computers
 | 
			
		||||
 * Wrapper class for pocket computers.
 | 
			
		||||
 */
 | 
			
		||||
public interface IPocketAccess
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the entity holding this item.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The holding entity. This may be {@code null}.
 | 
			
		||||
     * This must be called on the server thread.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The holding entity, or {@code null} if none exists.
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    Entity getEntity();
 | 
			
		||||
@@ -73,7 +74,7 @@ public interface IPocketAccess
 | 
			
		||||
     * @see #updateUpgradeNBTData()
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    NBTTagCompound getUpgradeNBTData();
 | 
			
		||||
    CompoundNBT getUpgradeNBTData();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Mark the upgrade-specific NBT as dirty.
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.pocket;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI;
 | 
			
		||||
@@ -19,7 +18,7 @@ import javax.annotation.Nullable;
 | 
			
		||||
/**
 | 
			
		||||
 * Additional peripherals for pocket computers.
 | 
			
		||||
 *
 | 
			
		||||
 * This is similar to {@link dan200.computercraft.api.turtle.ITurtleUpgrade}.
 | 
			
		||||
 * This is similar to {@link ITurtleUpgrade}.
 | 
			
		||||
 */
 | 
			
		||||
public interface IPocketUpgrade
 | 
			
		||||
{
 | 
			
		||||
@@ -54,6 +53,9 @@ public interface IPocketUpgrade
 | 
			
		||||
     * pocket computer which holds this upgrade. This item stack is also used to determine the upgrade given by
 | 
			
		||||
     * {@code pocket.equip()}/{@code pocket.unequip()}.
 | 
			
		||||
     *
 | 
			
		||||
     * Ideally this should be constant over a session. It is recommended that you cache
 | 
			
		||||
     * the item too, in order to prevent constructing it every time the method is called.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The item stack used for crafting. This can be {@link ItemStack#EMPTY} if crafting is disabled.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,11 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.redstone;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.util.EnumFacing;
 | 
			
		||||
import net.minecraft.util.Direction;
 | 
			
		||||
import net.minecraft.util.math.BlockPos;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
 | 
			
		||||
@@ -30,5 +29,5 @@ public interface IBundledRedstoneProvider
 | 
			
		||||
     * handle this block.
 | 
			
		||||
     * @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider)
 | 
			
		||||
     */
 | 
			
		||||
    int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side );
 | 
			
		||||
    int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Redstone", apiVersion = "${version}" )
 | 
			
		||||
package dan200.computercraft.api.redstone;
 | 
			
		||||
 | 
			
		||||
import net.minecraftforge.fml.common.API;
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle;
 | 
			
		||||
 | 
			
		||||
import com.mojang.authlib.GameProfile;
 | 
			
		||||
@@ -11,8 +10,8 @@ import dan200.computercraft.api.lua.ILuaContext;
 | 
			
		||||
import dan200.computercraft.api.lua.LuaException;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheral;
 | 
			
		||||
import net.minecraft.inventory.IInventory;
 | 
			
		||||
import net.minecraft.nbt.NBTTagCompound;
 | 
			
		||||
import net.minecraft.util.EnumFacing;
 | 
			
		||||
import net.minecraft.nbt.CompoundNBT;
 | 
			
		||||
import net.minecraft.util.Direction;
 | 
			
		||||
import net.minecraft.util.math.BlockPos;
 | 
			
		||||
import net.minecraft.util.math.Vec3d;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
@@ -54,8 +53,7 @@ public interface ITurtleAccess
 | 
			
		||||
     * @param world The new world to move it to
 | 
			
		||||
     * @param pos   The new position to move it to.
 | 
			
		||||
     * @return Whether the movement was successful. It may fail if the block was not loaded or the block placement
 | 
			
		||||
     * was cancelled. Note this will not check
 | 
			
		||||
     * {@link dan200.computercraft.api.permissions.ITurtlePermissionProvider#isBlockEnterable(World, BlockPos)}.
 | 
			
		||||
     * was cancelled.
 | 
			
		||||
     * @throws UnsupportedOperationException When attempting to teleport on the client side.
 | 
			
		||||
     */
 | 
			
		||||
    boolean teleportTo( @Nonnull World world, @Nonnull BlockPos pos );
 | 
			
		||||
@@ -84,10 +82,10 @@ public interface ITurtleAccess
 | 
			
		||||
     * Returns the world direction the turtle is currently facing.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The world direction the turtle is currently facing.
 | 
			
		||||
     * @see #setDirection(EnumFacing)
 | 
			
		||||
     * @see #setDirection(Direction)
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    EnumFacing getDirection();
 | 
			
		||||
    Direction getDirection();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Set the direction the turtle is facing. Note that this will not play a rotation animation, you will also need to
 | 
			
		||||
@@ -96,7 +94,7 @@ public interface ITurtleAccess
 | 
			
		||||
     * @param dir The new direction to set. This should be on either the x or z axis (so north, south, east or west).
 | 
			
		||||
     * @see #getDirection()
 | 
			
		||||
     */
 | 
			
		||||
    void setDirection( @Nonnull EnumFacing dir );
 | 
			
		||||
    void setDirection( @Nonnull Direction dir );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the currently selected slot in the turtle's inventory.
 | 
			
		||||
@@ -145,7 +143,9 @@ public interface ITurtleAccess
 | 
			
		||||
    GameProfile getOwningPlayer();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the inventory of this turtle
 | 
			
		||||
     * Get the inventory of this turtle.
 | 
			
		||||
     *
 | 
			
		||||
     * Note: this inventory should only be accessed and modified on the server thread.
 | 
			
		||||
     *
 | 
			
		||||
     * @return This turtle's inventory
 | 
			
		||||
     * @see #getItemHandler()
 | 
			
		||||
@@ -156,6 +156,8 @@ public interface ITurtleAccess
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the inventory of this turtle as an {@link IItemHandlerModifiable}.
 | 
			
		||||
     *
 | 
			
		||||
     * Note: this inventory should only be accessed and modified on the server thread.
 | 
			
		||||
     *
 | 
			
		||||
     * @return This turtle's inventory
 | 
			
		||||
     * @see #getInventory()
 | 
			
		||||
     * @see IItemHandlerModifiable
 | 
			
		||||
@@ -291,7 +293,7 @@ public interface ITurtleAccess
 | 
			
		||||
     * @see #updateUpgradeNBTData(TurtleSide)
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    NBTTagCompound getUpgradeNBTData( @Nullable TurtleSide side );
 | 
			
		||||
    CompoundNBT getUpgradeNBTData( @Nullable TurtleSide side );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Mark the upgrade-specific data as dirty on a specific side. This is required for the data to be synced to the
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaContext;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,24 +1,23 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.ComputerCraftAPI;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IPeripheral;
 | 
			
		||||
import dan200.computercraft.api.turtle.event.TurtleAttackEvent;
 | 
			
		||||
import dan200.computercraft.api.turtle.event.TurtleBlockEvent;
 | 
			
		||||
import net.minecraft.client.renderer.block.model.IBakedModel;
 | 
			
		||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
 | 
			
		||||
import net.minecraft.client.renderer.model.IBakedModel;
 | 
			
		||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraft.util.EnumFacing;
 | 
			
		||||
import net.minecraft.util.Direction;
 | 
			
		||||
import net.minecraft.util.ResourceLocation;
 | 
			
		||||
import net.minecraftforge.api.distmarker.Dist;
 | 
			
		||||
import net.minecraftforge.api.distmarker.OnlyIn;
 | 
			
		||||
import net.minecraftforge.event.entity.player.AttackEntityEvent;
 | 
			
		||||
import net.minecraftforge.event.world.BlockEvent;
 | 
			
		||||
import net.minecraftforge.fml.relauncher.Side;
 | 
			
		||||
import net.minecraftforge.fml.relauncher.SideOnly;
 | 
			
		||||
import org.apache.commons.lang3.tuple.Pair;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
@@ -44,17 +43,6 @@ public interface ITurtleUpgrade
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    ResourceLocation getUpgradeID();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets a numerical identifier representing this type of turtle upgrade,
 | 
			
		||||
     * for backwards compatibility with pre-1.76 worlds. If your upgrade was
 | 
			
		||||
     * not released for older ComputerCraft versions, you can return -1 here.
 | 
			
		||||
     * The turtle will fail registration if an already used positive ID is specified.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The legacy ID, or -1 if is needed.
 | 
			
		||||
     * @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade)
 | 
			
		||||
     */
 | 
			
		||||
    int getLegacyUpgradeID();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Return an unlocalised string to describe this type of turtle in turtle item names.
 | 
			
		||||
     *
 | 
			
		||||
@@ -79,6 +67,9 @@ public interface ITurtleUpgrade
 | 
			
		||||
     * with to create a turtle which holds this upgrade. This item stack is also used
 | 
			
		||||
     * to determine the upgrade given by {@code turtle.equip()}
 | 
			
		||||
     *
 | 
			
		||||
     * Ideally this should be constant over a session. It is recommended that you cache
 | 
			
		||||
     * the item too, in order to prevent constructing it every time the method is called.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The item stack to craft with, or {@link ItemStack#EMPTY} if it cannot be crafted.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
@@ -106,8 +97,8 @@ public interface ITurtleUpgrade
 | 
			
		||||
     * Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called
 | 
			
		||||
     * by the turtle, and the tool is required to do some work.
 | 
			
		||||
     *
 | 
			
		||||
     * Conforming implementations should fire {@link BlockEvent.BreakEvent} and {@link TurtleBlockEvent.Dig}for digging,
 | 
			
		||||
     * {@link AttackEntityEvent} and {@link TurtleAttackEvent} for attacking.
 | 
			
		||||
     * Conforming implementations should fire {@link BlockEvent.BreakEvent} and {@link TurtleBlockEvent.Dig} for
 | 
			
		||||
     * digging, {@link AttackEntityEvent} and {@link TurtleAttackEvent} for attacking.
 | 
			
		||||
     *
 | 
			
		||||
     * @param turtle    Access to the turtle that the tool resides on.
 | 
			
		||||
     * @param side      Which side of the turtle (left or right) the tool resides on.
 | 
			
		||||
@@ -121,7 +112,7 @@ public interface ITurtleUpgrade
 | 
			
		||||
     * to be called.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    default TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction )
 | 
			
		||||
    default TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull Direction direction )
 | 
			
		||||
    {
 | 
			
		||||
        return TurtleCommandResult.failure();
 | 
			
		||||
    }
 | 
			
		||||
@@ -130,7 +121,7 @@ public interface ITurtleUpgrade
 | 
			
		||||
     * Called to obtain the model to be used when rendering a turtle peripheral.
 | 
			
		||||
     *
 | 
			
		||||
     * This can be obtained from {@link net.minecraft.client.renderer.ItemModelMesher#getItemModel(ItemStack)},
 | 
			
		||||
     * {@link net.minecraft.client.renderer.block.model.ModelManager#getModel(ModelResourceLocation)} or any other
 | 
			
		||||
     * {@link net.minecraft.client.renderer.model.ModelManager#getModel(ModelResourceLocation)} or any other
 | 
			
		||||
     * source.
 | 
			
		||||
     *
 | 
			
		||||
     * @param turtle Access to the turtle that the upgrade resides on. This will be null when getting item models!
 | 
			
		||||
@@ -139,7 +130,7 @@ public interface ITurtleUpgrade
 | 
			
		||||
     * a transformation of {@code null} has the same effect as the identify matrix.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    @SideOnly( Side.CLIENT )
 | 
			
		||||
    @OnlyIn( Dist.CLIENT )
 | 
			
		||||
    Pair<IBakedModel, Matrix4f> getModel( @Nullable ITurtleAccess turtle, @Nonnull TurtleSide side );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,11 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.util.EnumFacing;
 | 
			
		||||
import net.minecraft.util.Direction;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
@@ -15,7 +14,7 @@ import javax.annotation.Nullable;
 | 
			
		||||
 * Used to indicate the result of executing a turtle command.
 | 
			
		||||
 *
 | 
			
		||||
 * @see ITurtleCommand#execute(ITurtleAccess)
 | 
			
		||||
 * @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)
 | 
			
		||||
 * @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)
 | 
			
		||||
 */
 | 
			
		||||
public final class TurtleCommandResult
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -12,12 +11,12 @@ package dan200.computercraft.api.turtle;
 | 
			
		||||
public enum TurtleSide
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * The turtle's left side (where the pickaxe usually is on a Wireless Mining Turtle)
 | 
			
		||||
     * The turtle's left side (where the pickaxe usually is on a Wireless Mining Turtle).
 | 
			
		||||
     */
 | 
			
		||||
    Left,
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The turtle's right side (where the modem usually is on a Wireless Mining Turtle)
 | 
			
		||||
     * The turtle's right side (where the modem usually is on a Wireless Mining Turtle).
 | 
			
		||||
     */
 | 
			
		||||
    Right,
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 
 | 
			
		||||
@@ -1,29 +1,28 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.util.EnumFacing;
 | 
			
		||||
import net.minecraft.util.Direction;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * An enum representing the different actions that an {@link ITurtleUpgrade} of type Tool may be called on to perform by
 | 
			
		||||
 * a turtle.
 | 
			
		||||
 *
 | 
			
		||||
 * @see ITurtleUpgrade#getType()
 | 
			
		||||
 * @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)
 | 
			
		||||
 * @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)
 | 
			
		||||
 */
 | 
			
		||||
public enum TurtleVerb
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * The turtle called {@code turtle.dig()}, {@code turtle.digUp()} or {@code turtle.digDown()}
 | 
			
		||||
     * The turtle called {@code turtle.dig()}, {@code turtle.digUp()} or {@code turtle.digDown()}.
 | 
			
		||||
     */
 | 
			
		||||
    Dig,
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The turtle called {@code turtle.attack()}, {@code turtle.attackUp()} or {@code turtle.attackDown()}
 | 
			
		||||
     * The turtle called {@code turtle.attack()}, {@code turtle.attackUp()} or {@code turtle.attackDown()}.
 | 
			
		||||
     */
 | 
			
		||||
    Attack,
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle.event;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -71,7 +70,7 @@ public enum TurtleAction
 | 
			
		||||
    EQUIP,
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Inspect a block in world
 | 
			
		||||
     * Inspect a block in world.
 | 
			
		||||
     *
 | 
			
		||||
     * @see TurtleBlockEvent.Inspect
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,13 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle.event;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleAccess;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
 | 
			
		||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
 | 
			
		||||
import net.minecraftforge.eventbus.api.Cancelable;
 | 
			
		||||
 | 
			
		||||
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-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle.event;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleAccess;
 | 
			
		||||
@@ -11,7 +10,7 @@ import dan200.computercraft.api.turtle.ITurtleUpgrade;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleSide;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleVerb;
 | 
			
		||||
import net.minecraft.entity.Entity;
 | 
			
		||||
import net.minecraft.util.EnumFacing;
 | 
			
		||||
import net.minecraft.util.Direction;
 | 
			
		||||
import net.minecraftforge.common.util.FakePlayer;
 | 
			
		||||
import net.minecraftforge.event.entity.player.AttackEntityEvent;
 | 
			
		||||
 | 
			
		||||
@@ -21,7 +20,7 @@ import java.util.Objects;
 | 
			
		||||
/**
 | 
			
		||||
 * Fired when a turtle attempts to attack an entity.
 | 
			
		||||
 *
 | 
			
		||||
 * This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)},
 | 
			
		||||
 * This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)},
 | 
			
		||||
 * as the base {@code turtle.attack()} command does not fire it.
 | 
			
		||||
 *
 | 
			
		||||
 * Note that such commands should also fire {@link AttackEntityEvent}, so you do not need to listen to both.
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle.event;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaContext;
 | 
			
		||||
@@ -12,14 +11,13 @@ import dan200.computercraft.api.turtle.ITurtleAccess;
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleSide;
 | 
			
		||||
import dan200.computercraft.api.turtle.TurtleVerb;
 | 
			
		||||
import net.minecraft.block.state.IBlockState;
 | 
			
		||||
import net.minecraft.block.BlockState;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraft.util.EnumFacing;
 | 
			
		||||
import net.minecraft.util.Direction;
 | 
			
		||||
import net.minecraft.util.math.BlockPos;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
import net.minecraftforge.common.util.FakePlayer;
 | 
			
		||||
import net.minecraftforge.event.world.BlockEvent;
 | 
			
		||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
@@ -37,7 +35,6 @@ import java.util.Objects;
 | 
			
		||||
 * Be aware that some events (such as {@link TurtleInventoryEvent}) do not necessarily interact
 | 
			
		||||
 * with a block, simply objects within that block space.
 | 
			
		||||
 */
 | 
			
		||||
@Cancelable
 | 
			
		||||
public abstract class TurtleBlockEvent extends TurtlePlayerEvent
 | 
			
		||||
{
 | 
			
		||||
    private final World world;
 | 
			
		||||
@@ -77,21 +74,20 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
 | 
			
		||||
    /**
 | 
			
		||||
     * Fired when a turtle attempts to dig a block.
 | 
			
		||||
     *
 | 
			
		||||
     * This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)},
 | 
			
		||||
     * This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)},
 | 
			
		||||
     * as the base {@code turtle.dig()} command does not fire it.
 | 
			
		||||
     *
 | 
			
		||||
     * Note that such commands should also fire {@link BlockEvent.BreakEvent}, so you do not need to listen to both.
 | 
			
		||||
     *
 | 
			
		||||
     * @see TurtleAction#DIG
 | 
			
		||||
     */
 | 
			
		||||
    @Cancelable
 | 
			
		||||
    public static class Dig extends TurtleBlockEvent
 | 
			
		||||
    {
 | 
			
		||||
        private final IBlockState block;
 | 
			
		||||
        private final BlockState block;
 | 
			
		||||
        private final ITurtleUpgrade upgrade;
 | 
			
		||||
        private final TurtleSide side;
 | 
			
		||||
 | 
			
		||||
        public Dig( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState block, @Nonnull ITurtleUpgrade upgrade, @Nonnull TurtleSide side )
 | 
			
		||||
        public Dig( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState block, @Nonnull ITurtleUpgrade upgrade, @Nonnull TurtleSide side )
 | 
			
		||||
        {
 | 
			
		||||
            super( turtle, TurtleAction.DIG, player, world, pos );
 | 
			
		||||
 | 
			
		||||
@@ -109,13 +105,13 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
 | 
			
		||||
         * @return The block which is going to be broken.
 | 
			
		||||
         */
 | 
			
		||||
        @Nonnull
 | 
			
		||||
        public IBlockState getBlock()
 | 
			
		||||
        public BlockState getBlock()
 | 
			
		||||
        {
 | 
			
		||||
            return block;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Get the upgrade doing the digging
 | 
			
		||||
         * Get the upgrade doing the digging.
 | 
			
		||||
         *
 | 
			
		||||
         * @return The upgrade doing the digging.
 | 
			
		||||
         */
 | 
			
		||||
@@ -142,7 +138,6 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
 | 
			
		||||
     *
 | 
			
		||||
     * @see TurtleAction#MOVE
 | 
			
		||||
     */
 | 
			
		||||
    @Cancelable
 | 
			
		||||
    public static class Move extends TurtleBlockEvent
 | 
			
		||||
    {
 | 
			
		||||
        public Move( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos )
 | 
			
		||||
@@ -156,7 +151,6 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
 | 
			
		||||
     *
 | 
			
		||||
     * @see TurtleAction#PLACE
 | 
			
		||||
     */
 | 
			
		||||
    @Cancelable
 | 
			
		||||
    public static class Place extends TurtleBlockEvent
 | 
			
		||||
    {
 | 
			
		||||
        private final ItemStack stack;
 | 
			
		||||
@@ -188,13 +182,12 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
 | 
			
		||||
     *
 | 
			
		||||
     * @see TurtleAction#INSPECT
 | 
			
		||||
     */
 | 
			
		||||
    @Cancelable
 | 
			
		||||
    public static class Inspect extends TurtleBlockEvent
 | 
			
		||||
    {
 | 
			
		||||
        private final IBlockState state;
 | 
			
		||||
        private final BlockState state;
 | 
			
		||||
        private final Map<String, Object> data;
 | 
			
		||||
 | 
			
		||||
        public Inspect( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull Map<String, Object> data )
 | 
			
		||||
        public Inspect( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull Map<String, Object> data )
 | 
			
		||||
        {
 | 
			
		||||
            super( turtle, TurtleAction.INSPECT, player, world, pos );
 | 
			
		||||
 | 
			
		||||
@@ -210,7 +203,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
 | 
			
		||||
         * @return The inspected block state.
 | 
			
		||||
         */
 | 
			
		||||
        @Nonnull
 | 
			
		||||
        public IBlockState getState()
 | 
			
		||||
        public BlockState getState()
 | 
			
		||||
        {
 | 
			
		||||
            return state;
 | 
			
		||||
        }
 | 
			
		||||
@@ -229,7 +222,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
 | 
			
		||||
        /**
 | 
			
		||||
         * Add new information to the inspection result. Note this will override fields with the same name.
 | 
			
		||||
         *
 | 
			
		||||
         * @param newData The data to add. Note all values should be convertable to Lua (see
 | 
			
		||||
         * @param newData The data to add. Note all values should be convertible to Lua (see
 | 
			
		||||
         *                {@link dan200.computercraft.api.peripheral.IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])}).
 | 
			
		||||
         */
 | 
			
		||||
        public void addData( @Nonnull Map<String, ?> newData )
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,12 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle.event;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleAccess;
 | 
			
		||||
import net.minecraftforge.fml.common.eventhandler.Event;
 | 
			
		||||
import net.minecraftforge.eventbus.api.Event;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,73 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle.event;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.lua.ILuaContext;
 | 
			
		||||
import dan200.computercraft.api.peripheral.IComputerAccess;
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleAccess;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Fired when a turtle gathers data on an item in its inventory.
 | 
			
		||||
 *
 | 
			
		||||
 * You may prevent items being inspected, or add additional information to the result. Be aware that this is fired on
 | 
			
		||||
 * the computer thread, and so any operations on it must be thread safe.
 | 
			
		||||
 *
 | 
			
		||||
 * @see TurtleAction#INSPECT_ITEM
 | 
			
		||||
 */
 | 
			
		||||
public class TurtleInspectItemEvent extends TurtleActionEvent
 | 
			
		||||
{
 | 
			
		||||
    private final ItemStack stack;
 | 
			
		||||
    private final Map<String, Object> data;
 | 
			
		||||
 | 
			
		||||
    public TurtleInspectItemEvent( @Nonnull ITurtleAccess turtle, @Nonnull ItemStack stack, @Nonnull Map<String, Object> data )
 | 
			
		||||
    {
 | 
			
		||||
        super( turtle, TurtleAction.INSPECT_ITEM );
 | 
			
		||||
 | 
			
		||||
        Objects.requireNonNull( stack, "stack cannot be null" );
 | 
			
		||||
        Objects.requireNonNull( data, "data cannot be null" );
 | 
			
		||||
        this.stack = stack;
 | 
			
		||||
        this.data = data;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The item which is currently being inspected.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The item stack which is being inspected. This should <b>not</b> be modified.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public ItemStack getStack()
 | 
			
		||||
    {
 | 
			
		||||
        return stack;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the "inspection data" from this item, which will be returned to the user.
 | 
			
		||||
     *
 | 
			
		||||
     * @return This items's inspection data.
 | 
			
		||||
     */
 | 
			
		||||
    @Nonnull
 | 
			
		||||
    public Map<String, Object> getData()
 | 
			
		||||
    {
 | 
			
		||||
        return data;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Add new information to the inspection result. Note this will override fields with the same name.
 | 
			
		||||
     *
 | 
			
		||||
     * @param newData The data to add. Note all values should be convertible to Lua (see
 | 
			
		||||
     *                {@link dan200.computercraft.api.peripheral.IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])}).
 | 
			
		||||
     */
 | 
			
		||||
    public void addData( @Nonnull Map<String, ?> newData )
 | 
			
		||||
    {
 | 
			
		||||
        Objects.requireNonNull( newData, "newData cannot be null" );
 | 
			
		||||
        data.putAll( newData );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle.event;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleAccess;
 | 
			
		||||
@@ -11,7 +10,6 @@ import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraft.util.math.BlockPos;
 | 
			
		||||
import net.minecraft.world.World;
 | 
			
		||||
import net.minecraftforge.common.util.FakePlayer;
 | 
			
		||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
 | 
			
		||||
import net.minecraftforge.items.IItemHandler;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
@@ -21,7 +19,6 @@ import java.util.Objects;
 | 
			
		||||
/**
 | 
			
		||||
 * Fired when a turtle attempts to interact with an inventory.
 | 
			
		||||
 */
 | 
			
		||||
@Cancelable
 | 
			
		||||
public abstract class TurtleInventoryEvent extends TurtleBlockEvent
 | 
			
		||||
{
 | 
			
		||||
    private final IItemHandler handler;
 | 
			
		||||
@@ -33,7 +30,7 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the inventory being interacted with
 | 
			
		||||
     * Get the inventory being interacted with.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The inventory being interacted with, {@code null} if the item will be dropped to/sucked from the world.
 | 
			
		||||
     */
 | 
			
		||||
@@ -48,7 +45,6 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent
 | 
			
		||||
     *
 | 
			
		||||
     * @see TurtleAction#SUCK
 | 
			
		||||
     */
 | 
			
		||||
    @Cancelable
 | 
			
		||||
    public static class Suck extends TurtleInventoryEvent
 | 
			
		||||
    {
 | 
			
		||||
        public Suck( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable IItemHandler handler )
 | 
			
		||||
@@ -62,7 +58,6 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent
 | 
			
		||||
     *
 | 
			
		||||
     * @see TurtleAction#DROP
 | 
			
		||||
     */
 | 
			
		||||
    @Cancelable
 | 
			
		||||
    public static class Drop extends TurtleInventoryEvent
 | 
			
		||||
    {
 | 
			
		||||
        private final ItemStack stack;
 | 
			
		||||
@@ -78,13 +73,12 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent
 | 
			
		||||
        /**
 | 
			
		||||
         * The item which will be inserted into the inventory/dropped on the ground.
 | 
			
		||||
         *
 | 
			
		||||
         * Note that this is a copy of the original stack, and so should not be modified, as that will have no effect.
 | 
			
		||||
         *
 | 
			
		||||
         * @return The item stack which will be dropped.
 | 
			
		||||
         * @return The item stack which will be dropped. This should <b>not</b> be modified.
 | 
			
		||||
         */
 | 
			
		||||
        @Nonnull
 | 
			
		||||
        public ItemStack getStack()
 | 
			
		||||
        {
 | 
			
		||||
            return stack.copy();
 | 
			
		||||
            return stack;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle.event;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleAccess;
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,90 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. 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.turtle.event;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.api.turtle.ITurtleAccess;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Fired when a turtle attempts to refuel from an item.
 | 
			
		||||
 *
 | 
			
		||||
 * One may use {@link #setCanceled(boolean, String)} to prevent refueling from this specific item. Additionally, you
 | 
			
		||||
 * may use {@link #setHandler(Handler)} to register a custom fuel provider.
 | 
			
		||||
 */
 | 
			
		||||
public class TurtleRefuelEvent extends TurtleActionEvent
 | 
			
		||||
{
 | 
			
		||||
    private final ItemStack stack;
 | 
			
		||||
    private Handler handler;
 | 
			
		||||
 | 
			
		||||
    public TurtleRefuelEvent( @Nonnull ITurtleAccess turtle, @Nonnull ItemStack stack )
 | 
			
		||||
    {
 | 
			
		||||
        super( turtle, TurtleAction.REFUEL );
 | 
			
		||||
 | 
			
		||||
        Objects.requireNonNull( turtle, "turtle cannot be null" );
 | 
			
		||||
        this.stack = stack;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the stack we are attempting to refuel from.
 | 
			
		||||
     *
 | 
			
		||||
     * Do not modify the returned stack - all modifications should be done within the {@link Handler}.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The stack to refuel from.
 | 
			
		||||
     */
 | 
			
		||||
    public ItemStack getStack()
 | 
			
		||||
    {
 | 
			
		||||
        return stack;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the refuel handler for this stack.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The refuel handler, or {@code null} if none has currently been set.
 | 
			
		||||
     * @see #setHandler(Handler)
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public Handler getHandler()
 | 
			
		||||
    {
 | 
			
		||||
        return handler;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Set the refuel handler for this stack.
 | 
			
		||||
     *
 | 
			
		||||
     * You should call this if you can actually refuel from this item, and ideally only if there are no existing
 | 
			
		||||
     * handlers.
 | 
			
		||||
     *
 | 
			
		||||
     * @param handler The new refuel handler.
 | 
			
		||||
     * @see #getHandler()
 | 
			
		||||
     */
 | 
			
		||||
    public void setHandler( @Nullable Handler handler )
 | 
			
		||||
    {
 | 
			
		||||
        this.handler = handler;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Handles refuelling a turtle from a specific item.
 | 
			
		||||
     */
 | 
			
		||||
    @FunctionalInterface
 | 
			
		||||
    public interface Handler
 | 
			
		||||
    {
 | 
			
		||||
        /**
 | 
			
		||||
         * Refuel a turtle using an item.
 | 
			
		||||
         *
 | 
			
		||||
         * @param turtle The turtle to refuel.
 | 
			
		||||
         * @param stack  The stack to refuel with.
 | 
			
		||||
         * @param slot   The slot the stack resides within. This may be used to modify the inventory afterwards.
 | 
			
		||||
         * @param limit  The maximum number of refuel operations to perform. This will often correspond to the number of
 | 
			
		||||
         *               items to consume.
 | 
			
		||||
         * @return The amount of fuel gained.
 | 
			
		||||
         */
 | 
			
		||||
        int refuel( @Nonnull ITurtleAccess turtle, @Nonnull ItemStack stack, int slot, int limit );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,10 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Turtle|Event", apiVersion = "${version}" )
 | 
			
		||||
package dan200.computercraft.api.turtle.event;
 | 
			
		||||
 | 
			
		||||
import net.minecraftforge.fml.common.API;
 | 
			
		||||
@@ -1,10 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of the public ComputerCraft API - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
 | 
			
		||||
 * For help using the API, and posting your mods, visit the forums at computercraft.info.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Turtle", apiVersion = "${version}" )
 | 
			
		||||
package dan200.computercraft.api.turtle;
 | 
			
		||||
 | 
			
		||||
import net.minecraftforge.fml.common.API;
 | 
			
		||||
@@ -1,108 +1,87 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.client;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.ComputerCraft;
 | 
			
		||||
import dan200.computercraft.client.render.TurtleModelLoader;
 | 
			
		||||
import dan200.computercraft.shared.media.items.ItemDiskLegacy;
 | 
			
		||||
import dan200.computercraft.shared.turtle.items.ItemTurtleBase;
 | 
			
		||||
import dan200.computercraft.shared.common.IColouredItem;
 | 
			
		||||
import dan200.computercraft.shared.media.items.ItemDisk;
 | 
			
		||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
 | 
			
		||||
import dan200.computercraft.shared.util.Colour;
 | 
			
		||||
import net.minecraft.client.Minecraft;
 | 
			
		||||
import net.minecraft.client.renderer.ItemMeshDefinition;
 | 
			
		||||
import net.minecraft.client.renderer.block.model.IBakedModel;
 | 
			
		||||
import net.minecraft.client.renderer.block.model.ModelBakery;
 | 
			
		||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
 | 
			
		||||
import net.minecraft.client.renderer.texture.TextureMap;
 | 
			
		||||
import net.minecraft.client.renderer.model.IBakedModel;
 | 
			
		||||
import net.minecraft.client.renderer.model.IUnbakedModel;
 | 
			
		||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
 | 
			
		||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
 | 
			
		||||
import net.minecraft.item.Item;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraft.util.ResourceLocation;
 | 
			
		||||
import net.minecraftforge.api.distmarker.Dist;
 | 
			
		||||
import net.minecraftforge.client.event.ColorHandlerEvent;
 | 
			
		||||
import net.minecraftforge.client.event.ModelBakeEvent;
 | 
			
		||||
import net.minecraftforge.client.event.ModelRegistryEvent;
 | 
			
		||||
import net.minecraftforge.client.event.TextureStitchEvent;
 | 
			
		||||
import net.minecraftforge.client.model.IModel;
 | 
			
		||||
import net.minecraftforge.client.model.BasicState;
 | 
			
		||||
import net.minecraftforge.client.model.ModelLoader;
 | 
			
		||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
 | 
			
		||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
 | 
			
		||||
import net.minecraftforge.fml.common.Mod;
 | 
			
		||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
 | 
			
		||||
import net.minecraftforge.fml.relauncher.Side;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Registers textures and models for items.
 | 
			
		||||
 */
 | 
			
		||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
 | 
			
		||||
public class ClientRegistry
 | 
			
		||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD )
 | 
			
		||||
public final class ClientRegistry
 | 
			
		||||
{
 | 
			
		||||
    private static final String[] EXTRA_MODELS = {
 | 
			
		||||
        "turtle_modem_off_left",
 | 
			
		||||
        "turtle_modem_on_left",
 | 
			
		||||
        "turtle_modem_off_right",
 | 
			
		||||
        "turtle_modem_on_right",
 | 
			
		||||
    private static final String[] EXTRA_MODELS = new String[] {
 | 
			
		||||
        "turtle_modem_normal_off_left",
 | 
			
		||||
        "turtle_modem_normal_on_left",
 | 
			
		||||
        "turtle_modem_normal_off_right",
 | 
			
		||||
        "turtle_modem_normal_on_right",
 | 
			
		||||
 | 
			
		||||
        "turtle_modem_advanced_off_left",
 | 
			
		||||
        "turtle_modem_advanced_on_left",
 | 
			
		||||
        "turtle_modem_advanced_off_right",
 | 
			
		||||
        "turtle_modem_advanced_on_right",
 | 
			
		||||
        "turtle_crafting_table_left",
 | 
			
		||||
        "turtle_crafting_table_right",
 | 
			
		||||
        "advanced_turtle_modem_off_left",
 | 
			
		||||
        "advanced_turtle_modem_on_left",
 | 
			
		||||
        "advanced_turtle_modem_off_right",
 | 
			
		||||
        "advanced_turtle_modem_on_right",
 | 
			
		||||
 | 
			
		||||
        "turtle_speaker_upgrade_left",
 | 
			
		||||
        "turtle_speaker_upgrade_right",
 | 
			
		||||
 | 
			
		||||
        "turtle_white",
 | 
			
		||||
        "turtle_colour",
 | 
			
		||||
        "turtle_elf_overlay",
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    private static final String[] EXTRA_TEXTURES = new String[] {
 | 
			
		||||
        // TODO: Gather these automatically from the model. Sadly the model loader isn't available
 | 
			
		||||
        //  when stitching textures.
 | 
			
		||||
        "block/turtle_colour",
 | 
			
		||||
        "block/turtle_elf_overlay",
 | 
			
		||||
        "block/turtle_crafty_face",
 | 
			
		||||
        "block/turtle_speaker_face",
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    private ClientRegistry() {}
 | 
			
		||||
 | 
			
		||||
    @SubscribeEvent
 | 
			
		||||
    public static void registerModels( ModelRegistryEvent event )
 | 
			
		||||
    {
 | 
			
		||||
        ModelLoaderRegistry.registerLoader( TurtleModelLoader.INSTANCE );
 | 
			
		||||
 | 
			
		||||
        // Register item models
 | 
			
		||||
        registerUniversalItemModel( ComputerCraft.Items.computer, "computer" );
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.commandComputer, 0, "command_computer" );
 | 
			
		||||
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.pocketComputer, 0, "pocket_computer" );
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.pocketComputer, 1, "advanced_pocket_computer" );
 | 
			
		||||
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.peripheral, 0, "peripheral" );
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.peripheral, 1, "wireless_modem" );
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.peripheral, 2, "monitor" );
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.peripheral, 3, "printer" );
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.peripheral, 4, "advanced_monitor" );
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.cable, 0, "cable" );
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.cable, 1, "wired_modem" );
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.advancedModem, 0, "advanced_modem" );
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.peripheral, 5, "speaker" );
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.wiredModemFull, 0, "wired_modem_full" );
 | 
			
		||||
 | 
			
		||||
        registerUniversalItemModel( ComputerCraft.Items.disk, "disk" );
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.diskExpanded, 0, "disk_expanded" );
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.treasureDisk, 0, "treasure_disk" );
 | 
			
		||||
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.printout, 0, "printout" );
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.printout, 1, "pages" );
 | 
			
		||||
        registerItemModel( ComputerCraft.Items.printout, 2, "book" );
 | 
			
		||||
 | 
			
		||||
        registerUniversalItemModel( ComputerCraft.Items.turtle, "turtle" );
 | 
			
		||||
        registerUniversalItemModel( ComputerCraft.Items.turtleExpanded, "turtle" );
 | 
			
		||||
        registerUniversalItemModel( ComputerCraft.Items.turtleAdvanced, "turtle_advanced" );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @SubscribeEvent
 | 
			
		||||
    public static void onTextureStitchEvent( TextureStitchEvent.Pre event )
 | 
			
		||||
    {
 | 
			
		||||
        // Load all textures for the extra models
 | 
			
		||||
        TextureMap map = event.getMap();
 | 
			
		||||
        for( String upgrade : EXTRA_MODELS )
 | 
			
		||||
        if( event.getMap() != Minecraft.getInstance().getTextureMap() ) return;
 | 
			
		||||
 | 
			
		||||
        for( String extra : EXTRA_TEXTURES )
 | 
			
		||||
        {
 | 
			
		||||
            IModel model = ModelLoaderRegistry.getModelOrMissing( new ResourceLocation( "computercraft", "block/" + upgrade ) );
 | 
			
		||||
            for( ResourceLocation texture : model.getTextures() ) map.registerSprite( texture );
 | 
			
		||||
            event.addSprite( new ResourceLocation( ComputerCraft.MOD_ID, extra ) );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -110,84 +89,79 @@ public class ClientRegistry
 | 
			
		||||
    public static void onModelBakeEvent( ModelBakeEvent event )
 | 
			
		||||
    {
 | 
			
		||||
        // Load all extra models
 | 
			
		||||
        for( String model : EXTRA_MODELS ) loadBlockModel( event, model );
 | 
			
		||||
        ModelLoader loader = event.getModelLoader();
 | 
			
		||||
        Map<ResourceLocation, IBakedModel> registry = event.getModelRegistry();
 | 
			
		||||
 | 
			
		||||
        for( String model : EXTRA_MODELS )
 | 
			
		||||
        {
 | 
			
		||||
            IBakedModel bakedModel = bake( loader, loader.getUnbakedModel( new ResourceLocation( ComputerCraft.MOD_ID, "item/" + model ) ) );
 | 
			
		||||
 | 
			
		||||
            if( bakedModel != null )
 | 
			
		||||
            {
 | 
			
		||||
                registry.put(
 | 
			
		||||
                    new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, model ), "inventory" ),
 | 
			
		||||
                    bakedModel
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // And load the custom turtle models in too.
 | 
			
		||||
        registry.put(
 | 
			
		||||
            new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_normal" ), "inventory" ),
 | 
			
		||||
            bake( loader, TurtleModelLoader.INSTANCE.loadModel( new ResourceLocation( ComputerCraft.MOD_ID, "item/turtle_normal" ) ) )
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        registry.put(
 | 
			
		||||
            new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_advanced" ), "inventory" ),
 | 
			
		||||
            bake( loader, TurtleModelLoader.INSTANCE.loadModel( new ResourceLocation( ComputerCraft.MOD_ID, "item/turtle_advanced" ) ) )
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @SubscribeEvent
 | 
			
		||||
    public static void onItemColours( ColorHandlerEvent.Item event )
 | 
			
		||||
    {
 | 
			
		||||
        event.getItemColors().registerItemColorHandler(
 | 
			
		||||
            ( stack, layer ) -> layer == 0 ? 0xFFFFFF : ((ItemDiskLegacy) stack.getItem()).getColour( stack ),
 | 
			
		||||
            ComputerCraft.Items.disk, ComputerCraft.Items.diskExpanded
 | 
			
		||||
        if( ComputerCraft.Items.disk == null || ComputerCraft.Blocks.turtleNormal == null )
 | 
			
		||||
        {
 | 
			
		||||
            ComputerCraft.log.warn( "Block/item registration has failed. Skipping registration of item colours." );
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        event.getItemColors().register(
 | 
			
		||||
            ( stack, layer ) -> layer == 1 ? ((ItemDisk) stack.getItem()).getColour( stack ) : 0xFFFFFF,
 | 
			
		||||
            ComputerCraft.Items.disk
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        event.getItemColors().registerItemColorHandler( ( stack, layer ) -> {
 | 
			
		||||
        event.getItemColors().register( ( stack, layer ) -> {
 | 
			
		||||
            switch( layer )
 | 
			
		||||
            {
 | 
			
		||||
                case 0:
 | 
			
		||||
                default:
 | 
			
		||||
                    return 0xFFFFFF;
 | 
			
		||||
                case 1:
 | 
			
		||||
                case 1: // Frame colour
 | 
			
		||||
                    return IColouredItem.getColourBasic( stack );
 | 
			
		||||
                case 2: // Light colour
 | 
			
		||||
                {
 | 
			
		||||
                    // Frame colour
 | 
			
		||||
                    int colour = ComputerCraft.Items.pocketComputer.getColour( stack );
 | 
			
		||||
                    return colour == -1 ? 0xFFFFFF : colour;
 | 
			
		||||
                }
 | 
			
		||||
                case 2:
 | 
			
		||||
                {
 | 
			
		||||
                    // Light colour
 | 
			
		||||
                    int colour = ComputerCraft.Items.pocketComputer.getLightState( stack );
 | 
			
		||||
                    return colour == -1 ? Colour.Black.getHex() : colour;
 | 
			
		||||
                    int light = ItemPocketComputer.getLightState( stack );
 | 
			
		||||
                    return light == -1 ? Colour.Black.getHex() : light;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }, ComputerCraft.Items.pocketComputer );
 | 
			
		||||
        }, ComputerCraft.Items.pocketComputerNormal, ComputerCraft.Items.pocketComputerAdvanced );
 | 
			
		||||
 | 
			
		||||
        // Setup turtle colours
 | 
			
		||||
        event.getItemColors().registerItemColorHandler( ( stack, tintIndex ) -> {
 | 
			
		||||
            if( tintIndex == 0 )
 | 
			
		||||
            {
 | 
			
		||||
                ItemTurtleBase turtle = (ItemTurtleBase) stack.getItem();
 | 
			
		||||
                int colour = turtle.getColour( stack );
 | 
			
		||||
                if( colour != -1 ) return colour;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return 0xFFFFFF;
 | 
			
		||||
        }, ComputerCraft.Blocks.turtle, ComputerCraft.Blocks.turtleExpanded, ComputerCraft.Blocks.turtleAdvanced );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void registerItemModel( Item item, int damage, String name )
 | 
			
		||||
    {
 | 
			
		||||
        ResourceLocation location = new ResourceLocation( ComputerCraft.MOD_ID, name );
 | 
			
		||||
        final ModelResourceLocation res = new ModelResourceLocation( location, "inventory" );
 | 
			
		||||
        ModelBakery.registerItemVariants( item, location );
 | 
			
		||||
        ModelLoader.setCustomModelResourceLocation( item, damage, res );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void registerUniversalItemModel( Item item, String mainModel )
 | 
			
		||||
    {
 | 
			
		||||
        ResourceLocation mainLocation = new ResourceLocation( ComputerCraft.MOD_ID, mainModel );
 | 
			
		||||
        ModelBakery.registerItemVariants( item, mainLocation );
 | 
			
		||||
 | 
			
		||||
        final ModelResourceLocation mainModelLocation = new ModelResourceLocation( mainLocation, "inventory" );
 | 
			
		||||
        ModelLoader.setCustomMeshDefinition( item, new ItemMeshDefinition()
 | 
			
		||||
        {
 | 
			
		||||
            @Nonnull
 | 
			
		||||
            @Override
 | 
			
		||||
            public ModelResourceLocation getModelLocation( @Nonnull ItemStack stack )
 | 
			
		||||
            {
 | 
			
		||||
                return mainModelLocation;
 | 
			
		||||
            }
 | 
			
		||||
        } );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void loadBlockModel( ModelBakeEvent event, String name )
 | 
			
		||||
    {
 | 
			
		||||
        IModel model = ModelLoaderRegistry.getModelOrMissing( new ResourceLocation( ComputerCraft.MOD_ID, "block/" + name ) );
 | 
			
		||||
        IBakedModel bakedModel = model.bake(
 | 
			
		||||
            model.getDefaultState(), DefaultVertexFormats.ITEM,
 | 
			
		||||
            location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite( location.toString() )
 | 
			
		||||
        event.getItemColors().register(
 | 
			
		||||
            ( stack, tintIndex ) -> tintIndex == 0 ? ((IColouredItem) stack.getItem()).getColour( stack ) : 0xFFFFFF,
 | 
			
		||||
            ComputerCraft.Blocks.turtleNormal, ComputerCraft.Blocks.turtleAdvanced
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        event.getModelRegistry().putObject( new ModelResourceLocation( ComputerCraft.MOD_ID + ":" + name, "inventory" ), bakedModel );
 | 
			
		||||
    private static IBakedModel bake( ModelLoader loader, IUnbakedModel model )
 | 
			
		||||
    {
 | 
			
		||||
        model.getTextures( loader::getUnbakedModel, new HashSet<>() );
 | 
			
		||||
 | 
			
		||||
        return model.bake(
 | 
			
		||||
            loader,
 | 
			
		||||
            ModelLoader.defaultTextureGetter(),
 | 
			
		||||
            new BasicState( model.getDefaultState(), false ), DefaultVertexFormats.BLOCK
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,8 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.client;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.shared.command.text.ChatHelpers;
 | 
			
		||||
@@ -12,8 +11,8 @@ import dan200.computercraft.shared.command.text.TableFormatter;
 | 
			
		||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
 | 
			
		||||
import net.minecraft.client.Minecraft;
 | 
			
		||||
import net.minecraft.client.gui.FontRenderer;
 | 
			
		||||
import net.minecraft.client.gui.GuiNewChat;
 | 
			
		||||
import net.minecraft.client.gui.GuiUtilRenderComponents;
 | 
			
		||||
import net.minecraft.client.gui.NewChatGui;
 | 
			
		||||
import net.minecraft.client.gui.RenderComponentsUtil;
 | 
			
		||||
import net.minecraft.util.math.MathHelper;
 | 
			
		||||
import net.minecraft.util.text.ITextComponent;
 | 
			
		||||
import net.minecraft.util.text.TextFormatting;
 | 
			
		||||
@@ -28,9 +27,9 @@ public class ClientTableFormatter implements TableFormatter
 | 
			
		||||
 | 
			
		||||
    private static Int2IntOpenHashMap lastHeights = new Int2IntOpenHashMap();
 | 
			
		||||
 | 
			
		||||
    private FontRenderer renderer()
 | 
			
		||||
    private static FontRenderer renderer()
 | 
			
		||||
    {
 | 
			
		||||
        return Minecraft.getMinecraft().fontRenderer;
 | 
			
		||||
        return Minecraft.getInstance().fontRenderer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -42,7 +41,7 @@ public class ClientTableFormatter implements TableFormatter
 | 
			
		||||
 | 
			
		||||
        FontRenderer renderer = renderer();
 | 
			
		||||
 | 
			
		||||
        float spaceWidth = renderer.getCharWidth( ' ' );
 | 
			
		||||
        float spaceWidth = renderer.getStringWidth( " " );
 | 
			
		||||
        int spaces = MathHelper.floor( extraWidth / spaceWidth );
 | 
			
		||||
        int extra = extraWidth - (int) (spaces * spaceWidth);
 | 
			
		||||
 | 
			
		||||
@@ -64,19 +63,19 @@ public class ClientTableFormatter implements TableFormatter
 | 
			
		||||
    @Override
 | 
			
		||||
    public void writeLine( int id, ITextComponent component )
 | 
			
		||||
    {
 | 
			
		||||
        Minecraft mc = Minecraft.getMinecraft();
 | 
			
		||||
        GuiNewChat chat = mc.ingameGUI.getChatGUI();
 | 
			
		||||
        Minecraft mc = Minecraft.getInstance();
 | 
			
		||||
        NewChatGui chat = mc.ingameGUI.getChatGUI();
 | 
			
		||||
 | 
			
		||||
        // Trim the text if it goes over the allowed length
 | 
			
		||||
        int maxWidth = MathHelper.floor( chat.getChatWidth() / chat.getChatScale() );
 | 
			
		||||
        List<ITextComponent> list = GuiUtilRenderComponents.splitText( component, maxWidth, mc.fontRenderer, false, false );
 | 
			
		||||
        int maxWidth = MathHelper.floor( chat.getChatWidth() / chat.getScale() );
 | 
			
		||||
        List<ITextComponent> list = RenderComponentsUtil.splitText( component, maxWidth, mc.fontRenderer, false, false );
 | 
			
		||||
        if( !list.isEmpty() ) chat.printChatMessageWithOptionalDeletion( list.get( 0 ), id );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int display( TableBuilder table )
 | 
			
		||||
    {
 | 
			
		||||
        GuiNewChat chat = Minecraft.getMinecraft().ingameGUI.getChatGUI();
 | 
			
		||||
        NewChatGui chat = Minecraft.getInstance().ingameGUI.getChatGUI();
 | 
			
		||||
 | 
			
		||||
        int lastHeight = lastHeights.get( table.getId() );
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,18 +1,17 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.client;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.ComputerCraft;
 | 
			
		||||
import net.minecraftforge.api.distmarker.Dist;
 | 
			
		||||
import net.minecraftforge.event.TickEvent;
 | 
			
		||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
 | 
			
		||||
import net.minecraftforge.fml.common.Mod;
 | 
			
		||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
 | 
			
		||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
 | 
			
		||||
import net.minecraftforge.fml.relauncher.Side;
 | 
			
		||||
 | 
			
		||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
 | 
			
		||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
 | 
			
		||||
public final class FrameInfo
 | 
			
		||||
{
 | 
			
		||||
    private static int tick;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,16 +1,15 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.client.gui;
 | 
			
		||||
 | 
			
		||||
import com.mojang.blaze3d.platform.GlStateManager;
 | 
			
		||||
import dan200.computercraft.core.terminal.TextBuffer;
 | 
			
		||||
import dan200.computercraft.shared.util.Palette;
 | 
			
		||||
import net.minecraft.client.Minecraft;
 | 
			
		||||
import net.minecraft.client.renderer.BufferBuilder;
 | 
			
		||||
import net.minecraft.client.renderer.GlStateManager;
 | 
			
		||||
import net.minecraft.client.renderer.Tessellator;
 | 
			
		||||
import net.minecraft.client.renderer.texture.TextureManager;
 | 
			
		||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
 | 
			
		||||
@@ -19,7 +18,7 @@ import org.lwjgl.opengl.GL11;
 | 
			
		||||
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
 | 
			
		||||
public class FixedWidthFontRenderer
 | 
			
		||||
public final class FixedWidthFontRenderer
 | 
			
		||||
{
 | 
			
		||||
    private static final ResourceLocation FONT = new ResourceLocation( "computercraft", "textures/gui/term_font.png" );
 | 
			
		||||
    public static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/term_background.png" );
 | 
			
		||||
@@ -39,7 +38,7 @@ public class FixedWidthFontRenderer
 | 
			
		||||
 | 
			
		||||
    private FixedWidthFontRenderer()
 | 
			
		||||
    {
 | 
			
		||||
        m_textureManager = Minecraft.getMinecraft().getTextureManager();
 | 
			
		||||
        m_textureManager = Minecraft.getInstance().getTextureManager();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void greyscaleify( double[] rgb )
 | 
			
		||||
@@ -93,7 +92,7 @@ public class FixedWidthFontRenderer
 | 
			
		||||
 | 
			
		||||
    private boolean isGreyScale( int colour )
 | 
			
		||||
    {
 | 
			
		||||
        return (colour == 0 || colour == 15 || colour == 7 || colour == 8);
 | 
			
		||||
        return colour == 0 || colour == 15 || colour == 7 || colour == 8;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void drawStringBackgroundPart( int x, int y, TextBuffer backgroundColour, double leftMarginSize, double rightMarginSize, boolean greyScale, Palette p )
 | 
			
		||||
@@ -129,9 +128,9 @@ public class FixedWidthFontRenderer
 | 
			
		||||
            }
 | 
			
		||||
            drawQuad( renderer, x + i * FONT_WIDTH, y, colour, FONT_WIDTH, p, greyScale );
 | 
			
		||||
        }
 | 
			
		||||
        GlStateManager.disableTexture2D();
 | 
			
		||||
        GlStateManager.disableTexture();
 | 
			
		||||
        tessellator.draw();
 | 
			
		||||
        GlStateManager.enableTexture2D();
 | 
			
		||||
        GlStateManager.enableTexture();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void drawStringTextPart( int x, int y, TextBuffer s, TextBuffer textColour, boolean greyScale, Palette p )
 | 
			
		||||
@@ -195,6 +194,6 @@ public class FixedWidthFontRenderer
 | 
			
		||||
    public void bindFont()
 | 
			
		||||
    {
 | 
			
		||||
        m_textureManager.bindTexture( FONT );
 | 
			
		||||
        GlStateManager.glTexParameteri( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
 | 
			
		||||
        GlStateManager.texParameter( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,194 +1,178 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.client.gui;
 | 
			
		||||
 | 
			
		||||
import com.mojang.blaze3d.platform.GlStateManager;
 | 
			
		||||
import dan200.computercraft.ComputerCraft;
 | 
			
		||||
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
 | 
			
		||||
import dan200.computercraft.shared.computer.blocks.TileComputer;
 | 
			
		||||
import dan200.computercraft.client.gui.widgets.WidgetWrapper;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.ClientComputer;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.IComputer;
 | 
			
		||||
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
 | 
			
		||||
import net.minecraft.client.gui.inventory.GuiContainer;
 | 
			
		||||
import net.minecraft.client.renderer.GlStateManager;
 | 
			
		||||
import net.minecraft.inventory.Container;
 | 
			
		||||
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
 | 
			
		||||
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
 | 
			
		||||
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
 | 
			
		||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
 | 
			
		||||
import net.minecraft.entity.player.PlayerInventory;
 | 
			
		||||
import net.minecraft.util.ResourceLocation;
 | 
			
		||||
import org.lwjgl.input.Keyboard;
 | 
			
		||||
import org.lwjgl.input.Mouse;
 | 
			
		||||
import net.minecraft.util.text.ITextComponent;
 | 
			
		||||
import org.lwjgl.glfw.GLFW;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
public class GuiComputer extends GuiContainer
 | 
			
		||||
public final class GuiComputer<T extends ContainerComputerBase> extends ContainerScreen<T>
 | 
			
		||||
{
 | 
			
		||||
    private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/corners.png" );
 | 
			
		||||
    private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( "computercraft", "textures/gui/corners_advanced.png" );
 | 
			
		||||
    private static final ResourceLocation BACKGROUND_COMMAND = new ResourceLocation( "computercraft", "textures/gui/corners_command.png" );
 | 
			
		||||
    public static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_normal.png" );
 | 
			
		||||
    public static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_advanced.png" );
 | 
			
		||||
    public static final ResourceLocation BACKGROUND_COMMAND = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_command.png" );
 | 
			
		||||
    public static final ResourceLocation BACKGROUND_COLOUR = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_colour.png" );
 | 
			
		||||
 | 
			
		||||
    private final ComputerFamily m_family;
 | 
			
		||||
    private final ClientComputer m_computer;
 | 
			
		||||
    private final int m_termWidth;
 | 
			
		||||
    private final int m_termHeight;
 | 
			
		||||
    private WidgetTerminal m_terminal;
 | 
			
		||||
 | 
			
		||||
    public GuiComputer( Container container, ComputerFamily family, ClientComputer computer, int termWidth, int termHeight )
 | 
			
		||||
    private WidgetTerminal terminal;
 | 
			
		||||
    private WidgetWrapper terminalWrapper;
 | 
			
		||||
 | 
			
		||||
    private GuiComputer(
 | 
			
		||||
        T container, PlayerInventory player, ITextComponent title, int termWidth, int termHeight
 | 
			
		||||
    )
 | 
			
		||||
    {
 | 
			
		||||
        super( container );
 | 
			
		||||
        m_family = family;
 | 
			
		||||
        m_computer = computer;
 | 
			
		||||
        super( container, player, title );
 | 
			
		||||
        m_family = container.getFamily();
 | 
			
		||||
        m_computer = (ClientComputer) container.getComputer();
 | 
			
		||||
        m_termWidth = termWidth;
 | 
			
		||||
        m_termHeight = termHeight;
 | 
			
		||||
        m_terminal = null;
 | 
			
		||||
        terminal = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public GuiComputer( Container container, ComputerFamily family, IComputer computer, int termWidth, int termHeight )
 | 
			
		||||
    public static GuiComputer<ContainerComputer> create( ContainerComputer container, PlayerInventory inventory, ITextComponent component )
 | 
			
		||||
    {
 | 
			
		||||
        this( container, family, (ClientComputer) computer, termWidth, termHeight );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public GuiComputer( TileComputer computer )
 | 
			
		||||
    {
 | 
			
		||||
        this(
 | 
			
		||||
            new ContainerComputer( computer ),
 | 
			
		||||
            computer.getFamily(),
 | 
			
		||||
            computer.createClientComputer(),
 | 
			
		||||
            ComputerCraft.terminalWidth_computer,
 | 
			
		||||
            ComputerCraft.terminalHeight_computer
 | 
			
		||||
        return new GuiComputer<>(
 | 
			
		||||
            container, inventory, component,
 | 
			
		||||
            ComputerCraft.terminalWidth_computer, ComputerCraft.terminalHeight_computer
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void initGui()
 | 
			
		||||
    public static GuiComputer<ContainerPocketComputer> createPocket( ContainerPocketComputer container, PlayerInventory inventory, ITextComponent component )
 | 
			
		||||
    {
 | 
			
		||||
        super.initGui();
 | 
			
		||||
        Keyboard.enableRepeatEvents( true );
 | 
			
		||||
        return new GuiComputer<>(
 | 
			
		||||
            container, inventory, component,
 | 
			
		||||
            ComputerCraft.terminalWidth_pocketComputer, ComputerCraft.terminalHeight_pocketComputer
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        m_terminal = new WidgetTerminal( 0, 0, m_termWidth, m_termHeight, () -> m_computer, 2, 2, 2, 2 );
 | 
			
		||||
        m_terminal.setAllowFocusLoss( false );
 | 
			
		||||
        xSize = m_terminal.getWidth() + 24;
 | 
			
		||||
        ySize = m_terminal.getHeight() + 24;
 | 
			
		||||
    public static GuiComputer<ContainerViewComputer> createView( ContainerViewComputer container, PlayerInventory inventory, ITextComponent component )
 | 
			
		||||
    {
 | 
			
		||||
        return new GuiComputer<>(
 | 
			
		||||
            container, inventory, component,
 | 
			
		||||
            container.getWidth(), container.getHeight()
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void init()
 | 
			
		||||
    {
 | 
			
		||||
        minecraft.keyboardListener.enableRepeatEvents( true );
 | 
			
		||||
 | 
			
		||||
        int termPxWidth = m_termWidth * FixedWidthFontRenderer.FONT_WIDTH;
 | 
			
		||||
        int termPxHeight = m_termHeight * FixedWidthFontRenderer.FONT_HEIGHT;
 | 
			
		||||
 | 
			
		||||
        xSize = termPxWidth + 4 + 24;
 | 
			
		||||
        ySize = termPxHeight + 4 + 24;
 | 
			
		||||
 | 
			
		||||
        super.init();
 | 
			
		||||
 | 
			
		||||
        terminal = new WidgetTerminal( minecraft, () -> m_computer, m_termWidth, m_termHeight, 2, 2, 2, 2 );
 | 
			
		||||
        terminalWrapper = new WidgetWrapper( terminal, 2 + 12 + guiLeft, 2 + 12 + guiTop, termPxWidth, termPxHeight );
 | 
			
		||||
 | 
			
		||||
        children.add( terminalWrapper );
 | 
			
		||||
        setFocused( terminalWrapper );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onGuiClosed()
 | 
			
		||||
    public void removed()
 | 
			
		||||
    {
 | 
			
		||||
        super.onGuiClosed();
 | 
			
		||||
        Keyboard.enableRepeatEvents( false );
 | 
			
		||||
        super.removed();
 | 
			
		||||
        children.remove( terminal );
 | 
			
		||||
        terminal = null;
 | 
			
		||||
        minecraft.keyboardListener.enableRepeatEvents( false );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean doesGuiPauseGame()
 | 
			
		||||
    public void tick()
 | 
			
		||||
    {
 | 
			
		||||
        return false;
 | 
			
		||||
        super.tick();
 | 
			
		||||
        terminal.update();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void updateScreen()
 | 
			
		||||
    public boolean keyPressed( int key, int scancode, int modifiers )
 | 
			
		||||
    {
 | 
			
		||||
        super.updateScreen();
 | 
			
		||||
        m_terminal.update();
 | 
			
		||||
        // Forward the tab key to the terminal, rather than moving between controls.
 | 
			
		||||
        if( key == GLFW.GLFW_KEY_TAB && getFocused() != null && getFocused() == terminalWrapper )
 | 
			
		||||
        {
 | 
			
		||||
            return getFocused().keyPressed( key, scancode, modifiers );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return super.keyPressed( key, scancode, modifiers );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void keyTyped( char c, int k ) throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        if( k == 1 )
 | 
			
		||||
        {
 | 
			
		||||
            super.keyTyped( c, k );
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            if( m_terminal.onKeyTyped( c, k ) ) keyHandled = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void mouseClicked( int x, int y, int button )
 | 
			
		||||
    {
 | 
			
		||||
        int startX = (width - m_terminal.getWidth()) / 2;
 | 
			
		||||
        int startY = (height - m_terminal.getHeight()) / 2;
 | 
			
		||||
        m_terminal.mouseClicked( x - startX, y - startY, button );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void handleMouseInput() throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        super.handleMouseInput();
 | 
			
		||||
 | 
			
		||||
        int x = Mouse.getEventX() * width / mc.displayWidth;
 | 
			
		||||
        int y = height - Mouse.getEventY() * height / mc.displayHeight - 1;
 | 
			
		||||
        int startX = (width - m_terminal.getWidth()) / 2;
 | 
			
		||||
        int startY = (height - m_terminal.getHeight()) / 2;
 | 
			
		||||
        m_terminal.handleMouseInput( x - startX, y - startY );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void handleKeyboardInput() throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        super.handleKeyboardInput();
 | 
			
		||||
        if( m_terminal.onKeyboardInput() ) keyHandled = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void drawGuiContainerForegroundLayer( int par1, int par2 )
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void drawGuiContainerBackgroundLayer( float var1, int var2, int var3 )
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void drawScreen( int mouseX, int mouseY, float f )
 | 
			
		||||
    public void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
 | 
			
		||||
    {
 | 
			
		||||
        // Work out where to draw
 | 
			
		||||
        int startX = (width - m_terminal.getWidth()) / 2;
 | 
			
		||||
        int startY = (height - m_terminal.getHeight()) / 2;
 | 
			
		||||
        int endX = startX + m_terminal.getWidth();
 | 
			
		||||
        int endY = startY + m_terminal.getHeight();
 | 
			
		||||
 | 
			
		||||
        // Draw background
 | 
			
		||||
        drawDefaultBackground();
 | 
			
		||||
        int startX = terminalWrapper.getX() - 2;
 | 
			
		||||
        int startY = terminalWrapper.getY() - 2;
 | 
			
		||||
        int endX = startX + terminalWrapper.getWidth() + 4;
 | 
			
		||||
        int endY = startY + terminalWrapper.getHeight() + 4;
 | 
			
		||||
 | 
			
		||||
        // Draw terminal
 | 
			
		||||
        m_terminal.draw( this.mc, startX, startY, mouseX, mouseY );
 | 
			
		||||
        terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() );
 | 
			
		||||
 | 
			
		||||
        // Draw a border around the terminal
 | 
			
		||||
        GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
 | 
			
		||||
        GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
 | 
			
		||||
        switch( m_family )
 | 
			
		||||
        {
 | 
			
		||||
            case Normal:
 | 
			
		||||
            default:
 | 
			
		||||
            {
 | 
			
		||||
                this.mc.getTextureManager().bindTexture( BACKGROUND );
 | 
			
		||||
                minecraft.getTextureManager().bindTexture( BACKGROUND_NORMAL );
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            case Advanced:
 | 
			
		||||
            {
 | 
			
		||||
                this.mc.getTextureManager().bindTexture( BACKGROUND_ADVANCED );
 | 
			
		||||
                minecraft.getTextureManager().bindTexture( BACKGROUND_ADVANCED );
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            case Command:
 | 
			
		||||
            {
 | 
			
		||||
                this.mc.getTextureManager().bindTexture( BACKGROUND_COMMAND );
 | 
			
		||||
                minecraft.getTextureManager().bindTexture( BACKGROUND_COMMAND );
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        blit( startX - 12, startY - 12, 12, 28, 12, 12 );
 | 
			
		||||
        blit( startX - 12, endY, 12, 40, 12, 12 );
 | 
			
		||||
        blit( endX, startY - 12, 24, 28, 12, 12 );
 | 
			
		||||
        blit( endX, endY, 24, 40, 12, 12 );
 | 
			
		||||
 | 
			
		||||
        blit( startX, startY - 12, 0, 0, endX - startX, 12 );
 | 
			
		||||
        blit( startX, endY, 0, 12, endX - startX, 12 );
 | 
			
		||||
 | 
			
		||||
        blit( startX - 12, startY, 0, 28, 12, endY - startY );
 | 
			
		||||
        blit( endX, startY, 36, 28, 12, endY - startY );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        drawTexturedModalRect( startX - 12, startY - 12, 12, 28, 12, 12 );
 | 
			
		||||
        drawTexturedModalRect( startX - 12, endY, 12, 40, 12, 16 );
 | 
			
		||||
        drawTexturedModalRect( endX, startY - 12, 24, 28, 12, 12 );
 | 
			
		||||
        drawTexturedModalRect( endX, endY, 24, 40, 12, 16 );
 | 
			
		||||
    @Override
 | 
			
		||||
    public void render( int mouseX, int mouseY, float partialTicks )
 | 
			
		||||
    {
 | 
			
		||||
        renderBackground();
 | 
			
		||||
        super.render( mouseX, mouseY, partialTicks );
 | 
			
		||||
        renderHoveredToolTip( mouseX, mouseY );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        drawTexturedModalRect( startX, startY - 12, 0, 0, endX - startX, 12 );
 | 
			
		||||
        drawTexturedModalRect( startX, endY, 0, 12, endX - startX, 16 );
 | 
			
		||||
 | 
			
		||||
        drawTexturedModalRect( startX - 12, startY, 0, 28, 12, endY - startY );
 | 
			
		||||
        drawTexturedModalRect( endX, startY, 36, 28, 12, endY - startY );
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY )
 | 
			
		||||
    {
 | 
			
		||||
        return (getFocused() != null && getFocused().mouseDragged( x, y, button, deltaX, deltaY ))
 | 
			
		||||
            || super.mouseDragged( x, y, button, deltaX, deltaY );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,52 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.client.gui;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.ComputerCraft;
 | 
			
		||||
import dan200.computercraft.shared.Config;
 | 
			
		||||
import net.minecraft.client.Minecraft;
 | 
			
		||||
import net.minecraft.client.gui.GuiScreen;
 | 
			
		||||
import net.minecraftforge.fml.client.IModGuiFactory;
 | 
			
		||||
import net.minecraftforge.fml.client.config.GuiConfig;
 | 
			
		||||
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
public class GuiConfigCC extends GuiConfig
 | 
			
		||||
{
 | 
			
		||||
    public GuiConfigCC( GuiScreen parentScreen )
 | 
			
		||||
    {
 | 
			
		||||
        super( parentScreen, Config.getConfigElements(), ComputerCraft.MOD_ID, false, false, "CC: Tweaked" );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static class Factory
 | 
			
		||||
        implements IModGuiFactory
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public void initialize( Minecraft minecraft )
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public boolean hasConfigGui()
 | 
			
		||||
        {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public GuiScreen createConfigGui( GuiScreen parentScreen )
 | 
			
		||||
        {
 | 
			
		||||
            return new GuiConfigCC( parentScreen );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public Set<RuntimeOptionCategoryElement> runtimeGuiCategories()
 | 
			
		||||
        {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,52 +1,47 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.client.gui;
 | 
			
		||||
 | 
			
		||||
import com.mojang.blaze3d.platform.GlStateManager;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
 | 
			
		||||
import net.minecraft.client.gui.inventory.GuiContainer;
 | 
			
		||||
import net.minecraft.client.renderer.GlStateManager;
 | 
			
		||||
import net.minecraft.client.resources.I18n;
 | 
			
		||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
 | 
			
		||||
import net.minecraft.entity.player.PlayerInventory;
 | 
			
		||||
import net.minecraft.util.ResourceLocation;
 | 
			
		||||
import net.minecraft.util.text.ITextComponent;
 | 
			
		||||
 | 
			
		||||
public class GuiDiskDrive extends GuiContainer
 | 
			
		||||
public class GuiDiskDrive extends ContainerScreen<ContainerDiskDrive>
 | 
			
		||||
{
 | 
			
		||||
    private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/diskdrive.png" );
 | 
			
		||||
    private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/disk_drive.png" );
 | 
			
		||||
 | 
			
		||||
    private final ContainerDiskDrive m_container;
 | 
			
		||||
 | 
			
		||||
    public GuiDiskDrive( ContainerDiskDrive container )
 | 
			
		||||
    public GuiDiskDrive( ContainerDiskDrive container, PlayerInventory player, ITextComponent title )
 | 
			
		||||
    {
 | 
			
		||||
        super( container );
 | 
			
		||||
        m_container = container;
 | 
			
		||||
        super( container, player, title );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void drawGuiContainerForegroundLayer( int par1, int par2 )
 | 
			
		||||
    protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
 | 
			
		||||
    {
 | 
			
		||||
        String title = m_container.getDiskDrive().getDisplayName().getUnformattedText();
 | 
			
		||||
        fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2, 6, 0x404040 );
 | 
			
		||||
        fontRenderer.drawString( I18n.format( "container.inventory" ), 8, (ySize - 96) + 2, 0x404040 );
 | 
			
		||||
        String title = this.title.getFormattedText();
 | 
			
		||||
        font.drawString( title, (xSize - font.getStringWidth( title )) / 2.0f, 6, 0x404040 );
 | 
			
		||||
        font.drawString( title, 8, ySize - 96 + 2, 0x404040 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void drawGuiContainerBackgroundLayer( float f, int i, int j )
 | 
			
		||||
    protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
 | 
			
		||||
    {
 | 
			
		||||
        GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
 | 
			
		||||
        this.mc.getTextureManager().bindTexture( BACKGROUND );
 | 
			
		||||
        int l = (width - xSize) / 2;
 | 
			
		||||
        int i1 = (height - ySize) / 2;
 | 
			
		||||
        drawTexturedModalRect( l, i1, 0, 0, xSize, ySize );
 | 
			
		||||
        GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
 | 
			
		||||
        minecraft.getTextureManager().bindTexture( BACKGROUND );
 | 
			
		||||
        blit( guiLeft, guiTop, 0, 0, xSize, ySize );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void drawScreen( int mouseX, int mouseY, float partialTicks )
 | 
			
		||||
    public void render( int mouseX, int mouseY, float partialTicks )
 | 
			
		||||
    {
 | 
			
		||||
        drawDefaultBackground();
 | 
			
		||||
        super.drawScreen( mouseX, mouseY, partialTicks );
 | 
			
		||||
        renderBackground();
 | 
			
		||||
        super.render( mouseX, mouseY, partialTicks );
 | 
			
		||||
        renderHoveredToolTip( mouseX, mouseY );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,24 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.client.gui;
 | 
			
		||||
 | 
			
		||||
import dan200.computercraft.ComputerCraft;
 | 
			
		||||
import dan200.computercraft.shared.media.inventory.ContainerHeldItem;
 | 
			
		||||
 | 
			
		||||
public class GuiPocketComputer extends GuiComputer
 | 
			
		||||
{
 | 
			
		||||
    public GuiPocketComputer( ContainerHeldItem container )
 | 
			
		||||
    {
 | 
			
		||||
        super(
 | 
			
		||||
            container,
 | 
			
		||||
            ComputerCraft.Items.pocketComputer.getFamily( container.getStack() ),
 | 
			
		||||
            ComputerCraft.Items.pocketComputer.createClientComputer( container.getStack() ),
 | 
			
		||||
            ComputerCraft.terminalWidth_pocketComputer,
 | 
			
		||||
            ComputerCraft.terminalHeight_pocketComputer
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,58 +1,50 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.client.gui;
 | 
			
		||||
 | 
			
		||||
import com.mojang.blaze3d.platform.GlStateManager;
 | 
			
		||||
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
 | 
			
		||||
import net.minecraft.client.gui.inventory.GuiContainer;
 | 
			
		||||
import net.minecraft.client.renderer.GlStateManager;
 | 
			
		||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
 | 
			
		||||
import net.minecraft.client.resources.I18n;
 | 
			
		||||
import net.minecraft.entity.player.PlayerInventory;
 | 
			
		||||
import net.minecraft.util.ResourceLocation;
 | 
			
		||||
import net.minecraft.util.text.ITextComponent;
 | 
			
		||||
 | 
			
		||||
public class GuiPrinter extends GuiContainer
 | 
			
		||||
public class GuiPrinter extends ContainerScreen<ContainerPrinter>
 | 
			
		||||
{
 | 
			
		||||
    private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printer.png" );
 | 
			
		||||
 | 
			
		||||
    private final ContainerPrinter m_container;
 | 
			
		||||
 | 
			
		||||
    public GuiPrinter( ContainerPrinter container )
 | 
			
		||||
    public GuiPrinter( ContainerPrinter container, PlayerInventory player, ITextComponent title )
 | 
			
		||||
    {
 | 
			
		||||
        super( container );
 | 
			
		||||
        m_container = container;
 | 
			
		||||
        super( container, player, title );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void drawGuiContainerForegroundLayer( int par1, int par2 )
 | 
			
		||||
    protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
 | 
			
		||||
    {
 | 
			
		||||
        String title = m_container.getPrinter().getDisplayName().getUnformattedText();
 | 
			
		||||
        fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2, 6, 0x404040 );
 | 
			
		||||
        fontRenderer.drawString( I18n.format( "container.inventory" ), 8, (ySize - 96) + 2, 0x404040 );
 | 
			
		||||
        String title = getTitle().getFormattedText();
 | 
			
		||||
        font.drawString( title, (xSize - font.getStringWidth( title )) / 2.0f, 6, 0x404040 );
 | 
			
		||||
        font.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void drawGuiContainerBackgroundLayer( float f, int i, int j )
 | 
			
		||||
    protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
 | 
			
		||||
    {
 | 
			
		||||
        GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
 | 
			
		||||
        this.mc.getTextureManager().bindTexture( BACKGROUND );
 | 
			
		||||
        int startX = (width - xSize) / 2;
 | 
			
		||||
        int startY = (height - ySize) / 2;
 | 
			
		||||
        drawTexturedModalRect( startX, startY, 0, 0, xSize, ySize );
 | 
			
		||||
        GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
 | 
			
		||||
        minecraft.getTextureManager().bindTexture( BACKGROUND );
 | 
			
		||||
        blit( guiLeft, guiTop, 0, 0, xSize, ySize );
 | 
			
		||||
 | 
			
		||||
        boolean printing = m_container.isPrinting();
 | 
			
		||||
        if( printing )
 | 
			
		||||
        {
 | 
			
		||||
            drawTexturedModalRect( startX + 34, startY + 21, 176, 0, 25, 45 );
 | 
			
		||||
        }
 | 
			
		||||
        if( getContainer().isPrinting() ) blit( guiLeft + 34, guiTop + 21, 176, 0, 25, 45 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void drawScreen( int mouseX, int mouseY, float partialTicks )
 | 
			
		||||
    public void render( int mouseX, int mouseY, float partialTicks )
 | 
			
		||||
    {
 | 
			
		||||
        drawDefaultBackground();
 | 
			
		||||
        super.drawScreen( mouseX, mouseY, partialTicks );
 | 
			
		||||
        renderBackground();
 | 
			
		||||
        super.render( mouseX, mouseY, partialTicks );
 | 
			
		||||
        renderHoveredToolTip( mouseX, mouseY );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,23 +1,22 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.client.gui;
 | 
			
		||||
 | 
			
		||||
import com.mojang.blaze3d.platform.GlStateManager;
 | 
			
		||||
import dan200.computercraft.core.terminal.TextBuffer;
 | 
			
		||||
import dan200.computercraft.shared.media.inventory.ContainerHeldItem;
 | 
			
		||||
import dan200.computercraft.shared.common.ContainerHeldItem;
 | 
			
		||||
import dan200.computercraft.shared.media.items.ItemPrintout;
 | 
			
		||||
import net.minecraft.client.gui.inventory.GuiContainer;
 | 
			
		||||
import net.minecraft.client.renderer.GlStateManager;
 | 
			
		||||
import org.lwjgl.input.Mouse;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
 | 
			
		||||
import net.minecraft.entity.player.PlayerInventory;
 | 
			
		||||
import net.minecraft.util.text.ITextComponent;
 | 
			
		||||
import org.lwjgl.glfw.GLFW;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.client.render.PrintoutRenderer.*;
 | 
			
		||||
 | 
			
		||||
public class GuiPrintout extends GuiContainer
 | 
			
		||||
public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
 | 
			
		||||
{
 | 
			
		||||
    private final boolean m_book;
 | 
			
		||||
    private final int m_pages;
 | 
			
		||||
@@ -25,9 +24,11 @@ public class GuiPrintout extends GuiContainer
 | 
			
		||||
    private final TextBuffer[] m_colours;
 | 
			
		||||
    private int m_page;
 | 
			
		||||
 | 
			
		||||
    public GuiPrintout( ContainerHeldItem container )
 | 
			
		||||
    public GuiPrintout( ContainerHeldItem container, PlayerInventory player, ITextComponent title )
 | 
			
		||||
    {
 | 
			
		||||
        super( container );
 | 
			
		||||
        super( container, player, title );
 | 
			
		||||
 | 
			
		||||
        ySize = Y_SIZE;
 | 
			
		||||
 | 
			
		||||
        String[] text = ItemPrintout.getText( container.getStack() );
 | 
			
		||||
        m_text = new TextBuffer[text.length];
 | 
			
		||||
@@ -39,75 +40,70 @@ public class GuiPrintout extends GuiContainer
 | 
			
		||||
 | 
			
		||||
        m_page = 0;
 | 
			
		||||
        m_pages = Math.max( m_text.length / ItemPrintout.LINES_PER_PAGE, 1 );
 | 
			
		||||
        m_book = ItemPrintout.getType( container.getStack() ) == ItemPrintout.Type.Book;
 | 
			
		||||
        m_book = ((ItemPrintout) container.getStack().getItem()).getType() == ItemPrintout.Type.BOOK;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean doesGuiPauseGame()
 | 
			
		||||
    public boolean keyPressed( int key, int scancode, int modifiers )
 | 
			
		||||
    {
 | 
			
		||||
        if( super.keyPressed( key, scancode, modifiers ) ) return true;
 | 
			
		||||
 | 
			
		||||
        if( key == GLFW.GLFW_KEY_RIGHT )
 | 
			
		||||
        {
 | 
			
		||||
            if( m_page < m_pages - 1 ) m_page++;
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if( key == GLFW.GLFW_KEY_LEFT )
 | 
			
		||||
        {
 | 
			
		||||
            if( m_page > 0 ) m_page--;
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void keyTyped( char c, int k ) throws IOException
 | 
			
		||||
    public boolean mouseScrolled( double x, double y, double delta )
 | 
			
		||||
    {
 | 
			
		||||
        super.keyTyped( c, k );
 | 
			
		||||
 | 
			
		||||
        if( k == 205 )
 | 
			
		||||
        if( super.mouseScrolled( x, y, delta ) ) return true;
 | 
			
		||||
        if( delta < 0 )
 | 
			
		||||
        {
 | 
			
		||||
            // Right
 | 
			
		||||
            // Scroll up goes to the next page
 | 
			
		||||
            if( m_page < m_pages - 1 ) m_page++;
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        else if( k == 203 )
 | 
			
		||||
 | 
			
		||||
        if( delta > 0 )
 | 
			
		||||
        {
 | 
			
		||||
            // Left
 | 
			
		||||
            // Scroll down goes to the previous page
 | 
			
		||||
            if( m_page > 0 ) m_page--;
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void handleMouseInput() throws IOException
 | 
			
		||||
    public void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
 | 
			
		||||
    {
 | 
			
		||||
        super.handleMouseInput();
 | 
			
		||||
 | 
			
		||||
        int mouseWheelChange = Mouse.getEventDWheel();
 | 
			
		||||
        if( mouseWheelChange < 0 )
 | 
			
		||||
        {
 | 
			
		||||
            // Up
 | 
			
		||||
            if( m_page < m_pages - 1 ) m_page++;
 | 
			
		||||
        }
 | 
			
		||||
        else if( mouseWheelChange > 0 )
 | 
			
		||||
        {
 | 
			
		||||
            // Down
 | 
			
		||||
            if( m_page > 0 ) m_page--;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void drawGuiContainerForegroundLayer( int par1, int par2 )
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void drawGuiContainerBackgroundLayer( float var1, int var2, int var3 )
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void drawScreen( int mouseX, int mouseY, float f )
 | 
			
		||||
    {
 | 
			
		||||
        // Draw background
 | 
			
		||||
        zLevel = zLevel - 1;
 | 
			
		||||
        drawDefaultBackground();
 | 
			
		||||
        zLevel = zLevel + 1;
 | 
			
		||||
 | 
			
		||||
        // Draw the printout
 | 
			
		||||
        GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
 | 
			
		||||
        GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
 | 
			
		||||
        GlStateManager.enableDepthTest();
 | 
			
		||||
 | 
			
		||||
        int startY = (height - Y_SIZE) / 2;
 | 
			
		||||
        int startX = (width - X_SIZE) / 2;
 | 
			
		||||
        drawBorder( guiLeft, guiTop, blitOffset, m_page, m_pages, m_book );
 | 
			
		||||
        drawText( guiLeft + X_TEXT_MARGIN, guiTop + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        drawBorder( startX, startY, zLevel, m_page, m_pages, m_book );
 | 
			
		||||
        drawText( startX + X_TEXT_MARGIN, startY + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours );
 | 
			
		||||
    @Override
 | 
			
		||||
    public void render( int mouseX, int mouseY, float partialTicks )
 | 
			
		||||
    {
 | 
			
		||||
        // We must take the background further back in order to not overlap with our printed pages.
 | 
			
		||||
        blitOffset--;
 | 
			
		||||
        renderBackground();
 | 
			
		||||
        blitOffset++;
 | 
			
		||||
 | 
			
		||||
        super.render( mouseX, mouseY, partialTicks );
 | 
			
		||||
        renderHoveredToolTip( mouseX, mouseY );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,154 +1,138 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.client.gui;
 | 
			
		||||
 | 
			
		||||
import com.mojang.blaze3d.platform.GlStateManager;
 | 
			
		||||
import dan200.computercraft.ComputerCraft;
 | 
			
		||||
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
 | 
			
		||||
import dan200.computercraft.client.gui.widgets.WidgetWrapper;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.ClientComputer;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
 | 
			
		||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
 | 
			
		||||
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
 | 
			
		||||
import net.minecraft.client.Minecraft;
 | 
			
		||||
import net.minecraft.client.gui.inventory.GuiContainer;
 | 
			
		||||
import net.minecraft.client.renderer.GlStateManager;
 | 
			
		||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
 | 
			
		||||
import net.minecraft.entity.player.PlayerInventory;
 | 
			
		||||
import net.minecraft.util.ResourceLocation;
 | 
			
		||||
import org.lwjgl.input.Keyboard;
 | 
			
		||||
import org.lwjgl.input.Mouse;
 | 
			
		||||
import net.minecraft.util.text.ITextComponent;
 | 
			
		||||
import org.lwjgl.glfw.GLFW;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
public class GuiTurtle extends GuiContainer
 | 
			
		||||
public class GuiTurtle extends ContainerScreen<ContainerTurtle>
 | 
			
		||||
{
 | 
			
		||||
    private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/turtle.png" );
 | 
			
		||||
    private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( "computercraft", "textures/gui/turtle_normal.png" );
 | 
			
		||||
    private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( "computercraft", "textures/gui/turtle_advanced.png" );
 | 
			
		||||
 | 
			
		||||
    private ContainerTurtle m_container;
 | 
			
		||||
 | 
			
		||||
    private final ComputerFamily m_family;
 | 
			
		||||
    private final ClientComputer m_computer;
 | 
			
		||||
    private WidgetTerminal m_terminalGui;
 | 
			
		||||
 | 
			
		||||
    public GuiTurtle( TileTurtle turtle, ContainerTurtle container )
 | 
			
		||||
    private WidgetTerminal terminal;
 | 
			
		||||
    private WidgetWrapper terminalWrapper;
 | 
			
		||||
 | 
			
		||||
    public GuiTurtle( ContainerTurtle container, PlayerInventory player, ITextComponent title )
 | 
			
		||||
    {
 | 
			
		||||
        super( container );
 | 
			
		||||
        super( container, player, title );
 | 
			
		||||
 | 
			
		||||
        m_container = container;
 | 
			
		||||
        m_family = turtle.getFamily();
 | 
			
		||||
        m_computer = turtle.getClientComputer();
 | 
			
		||||
        m_family = container.getFamily();
 | 
			
		||||
        m_computer = (ClientComputer) container.getComputer();
 | 
			
		||||
 | 
			
		||||
        xSize = 254;
 | 
			
		||||
        ySize = 217;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void initGui()
 | 
			
		||||
    protected void init()
 | 
			
		||||
    {
 | 
			
		||||
        super.initGui();
 | 
			
		||||
        Keyboard.enableRepeatEvents( true );
 | 
			
		||||
        m_terminalGui = new WidgetTerminal(
 | 
			
		||||
            (width - xSize) / 2 + 8,
 | 
			
		||||
            (height - ySize) / 2 + 8,
 | 
			
		||||
        super.init();
 | 
			
		||||
        minecraft.keyboardListener.enableRepeatEvents( true );
 | 
			
		||||
 | 
			
		||||
        int termPxWidth = ComputerCraft.terminalWidth_turtle * FixedWidthFontRenderer.FONT_WIDTH;
 | 
			
		||||
        int termPxHeight = ComputerCraft.terminalHeight_turtle * FixedWidthFontRenderer.FONT_HEIGHT;
 | 
			
		||||
 | 
			
		||||
        terminal = new WidgetTerminal(
 | 
			
		||||
            minecraft, () -> m_computer,
 | 
			
		||||
            ComputerCraft.terminalWidth_turtle,
 | 
			
		||||
            ComputerCraft.terminalHeight_turtle,
 | 
			
		||||
            () -> m_computer,
 | 
			
		||||
            2, 2, 2, 2
 | 
			
		||||
        );
 | 
			
		||||
        m_terminalGui.setAllowFocusLoss( false );
 | 
			
		||||
        terminalWrapper = new WidgetWrapper( terminal, 2 + 8 + guiLeft, 2 + 8 + guiTop, termPxWidth, termPxHeight );
 | 
			
		||||
 | 
			
		||||
        children.add( terminalWrapper );
 | 
			
		||||
        setFocused( terminalWrapper );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onGuiClosed()
 | 
			
		||||
    public void removed()
 | 
			
		||||
    {
 | 
			
		||||
        super.onGuiClosed();
 | 
			
		||||
        Keyboard.enableRepeatEvents( false );
 | 
			
		||||
        super.removed();
 | 
			
		||||
        children.remove( terminal );
 | 
			
		||||
        terminal = null;
 | 
			
		||||
        minecraft.keyboardListener.enableRepeatEvents( false );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void updateScreen()
 | 
			
		||||
    public void tick()
 | 
			
		||||
    {
 | 
			
		||||
        super.updateScreen();
 | 
			
		||||
        m_terminalGui.update();
 | 
			
		||||
        super.tick();
 | 
			
		||||
        terminal.update();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void keyTyped( char c, int k ) throws IOException
 | 
			
		||||
    public boolean keyPressed( int key, int scancode, int modifiers )
 | 
			
		||||
    {
 | 
			
		||||
        if( k == 1 )
 | 
			
		||||
        // Forward the tab key to the terminal, rather than moving between controls.
 | 
			
		||||
        if( key == GLFW.GLFW_KEY_TAB && getFocused() != null && getFocused() == terminalWrapper )
 | 
			
		||||
        {
 | 
			
		||||
            super.keyTyped( c, k );
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            if( m_terminalGui.onKeyTyped( c, k ) ) keyHandled = true;
 | 
			
		||||
        }
 | 
			
		||||
            return getFocused().keyPressed( key, scancode, modifiers );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void mouseClicked( int x, int y, int button ) throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        super.mouseClicked( x, y, button );
 | 
			
		||||
        m_terminalGui.mouseClicked( x, y, button );
 | 
			
		||||
        return super.keyPressed( key, scancode, modifiers );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void handleMouseInput() throws IOException
 | 
			
		||||
    private void drawSelectionSlot( boolean advanced )
 | 
			
		||||
    {
 | 
			
		||||
        super.handleMouseInput();
 | 
			
		||||
        int x = Mouse.getEventX() * this.width / mc.displayWidth;
 | 
			
		||||
        int y = this.height - Mouse.getEventY() * this.height / mc.displayHeight - 1;
 | 
			
		||||
        m_terminalGui.handleMouseInput( x, y );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void handleKeyboardInput() throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        super.handleKeyboardInput();
 | 
			
		||||
        if( m_terminalGui.onKeyboardInput() ) keyHandled = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected void drawSelectionSlot( boolean advanced )
 | 
			
		||||
    {
 | 
			
		||||
        int x = (width - xSize) / 2;
 | 
			
		||||
        int y = (height - ySize) / 2;
 | 
			
		||||
 | 
			
		||||
        // Draw selection slot
 | 
			
		||||
        int slot = m_container.getSelectedSlot();
 | 
			
		||||
        if( slot >= 0 )
 | 
			
		||||
        {
 | 
			
		||||
            GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
 | 
			
		||||
            int slotX = (slot % 4);
 | 
			
		||||
            int slotY = (slot / 4);
 | 
			
		||||
            this.mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND );
 | 
			
		||||
            drawTexturedModalRect( x + m_container.m_turtleInvStartX - 2 + slotX * 18, y + m_container.m_playerInvStartY - 2 + slotY * 18, 0, 217, 24, 24 );
 | 
			
		||||
            GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
 | 
			
		||||
            int slotX = slot % 4;
 | 
			
		||||
            int slotY = slot / 4;
 | 
			
		||||
            minecraft.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
 | 
			
		||||
            blit( guiLeft + ContainerTurtle.TURTLE_START_X - 2 + slotX * 18, guiTop + ContainerTurtle.PLAYER_START_Y - 2 + slotY * 18, 0, 217, 24, 24 );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void drawGuiContainerBackgroundLayer( float f, int mouseX, int mouseY )
 | 
			
		||||
    protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
 | 
			
		||||
    {
 | 
			
		||||
        // Draw term
 | 
			
		||||
        boolean advanced = (m_family == ComputerFamily.Advanced);
 | 
			
		||||
        m_terminalGui.draw( Minecraft.getMinecraft(), 0, 0, mouseX, mouseY );
 | 
			
		||||
        boolean advanced = m_family == ComputerFamily.Advanced;
 | 
			
		||||
        terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() );
 | 
			
		||||
 | 
			
		||||
        // Draw border/inventory
 | 
			
		||||
        GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
 | 
			
		||||
        this.mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND );
 | 
			
		||||
        int x = (width - xSize) / 2;
 | 
			
		||||
        int y = (height - ySize) / 2;
 | 
			
		||||
        drawTexturedModalRect( x, y, 0, 0, xSize, ySize );
 | 
			
		||||
        GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
 | 
			
		||||
        minecraft.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
 | 
			
		||||
        blit( guiLeft, guiTop, 0, 0, xSize, ySize );
 | 
			
		||||
 | 
			
		||||
        drawSelectionSlot( advanced );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void drawScreen( int mouseX, int mouseY, float partialTicks )
 | 
			
		||||
    public void render( int mouseX, int mouseY, float partialTicks )
 | 
			
		||||
    {
 | 
			
		||||
        drawDefaultBackground();
 | 
			
		||||
        super.drawScreen( mouseX, mouseY, partialTicks );
 | 
			
		||||
        renderBackground();
 | 
			
		||||
        super.render( mouseX, mouseY, partialTicks );
 | 
			
		||||
        renderHoveredToolTip( mouseX, mouseY );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY )
 | 
			
		||||
    {
 | 
			
		||||
        return (getFocused() != null && getFocused().mouseDragged( x, y, button, deltaX, deltaY ))
 | 
			
		||||
            || super.mouseDragged( x, y, button, deltaX, deltaY );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,84 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.client.gui.widgets;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.client.Minecraft;
 | 
			
		||||
import net.minecraft.client.gui.Gui;
 | 
			
		||||
 | 
			
		||||
public abstract class Widget extends Gui
 | 
			
		||||
{
 | 
			
		||||
    private int m_xPosition;
 | 
			
		||||
    private int m_yPosition;
 | 
			
		||||
    private int m_width;
 | 
			
		||||
    private int m_height;
 | 
			
		||||
 | 
			
		||||
    protected Widget( int x, int y, int width, int height )
 | 
			
		||||
    {
 | 
			
		||||
        m_xPosition = x;
 | 
			
		||||
        m_yPosition = y;
 | 
			
		||||
        m_width = width;
 | 
			
		||||
        m_height = height;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getXPosition()
 | 
			
		||||
    {
 | 
			
		||||
        return m_xPosition;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getYPosition()
 | 
			
		||||
    {
 | 
			
		||||
        return m_yPosition;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getWidth()
 | 
			
		||||
    {
 | 
			
		||||
        return m_width;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getHeight()
 | 
			
		||||
    {
 | 
			
		||||
        return m_height;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void update()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void draw( Minecraft mc, int xOrigin, int yOrigin, int mouseX, int mouseY )
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void handleMouseInput( int mouseX, int mouseY )
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean onKeyboardInput()
 | 
			
		||||
    {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public void handleKeyboardInput()
 | 
			
		||||
    {
 | 
			
		||||
        onKeyboardInput();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void mouseClicked( int mouseX, int mouseY, int mouseButton )
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean onKeyTyped( char c, int k )
 | 
			
		||||
    {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public void keyTyped( char c, int k )
 | 
			
		||||
    {
 | 
			
		||||
        onKeyTyped( c, k );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,100 +1,108 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package dan200.computercraft.client.gui.widgets;
 | 
			
		||||
 | 
			
		||||
import com.mojang.blaze3d.platform.GlStateManager;
 | 
			
		||||
import dan200.computercraft.client.FrameInfo;
 | 
			
		||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
 | 
			
		||||
import dan200.computercraft.core.terminal.Terminal;
 | 
			
		||||
import dan200.computercraft.core.terminal.TextBuffer;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.ClientComputer;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.IComputer;
 | 
			
		||||
import dan200.computercraft.shared.computer.core.IComputerContainer;
 | 
			
		||||
import dan200.computercraft.shared.util.Colour;
 | 
			
		||||
import dan200.computercraft.shared.util.Palette;
 | 
			
		||||
import net.minecraft.client.Minecraft;
 | 
			
		||||
import net.minecraft.client.gui.GuiScreen;
 | 
			
		||||
import net.minecraft.client.renderer.GlStateManager;
 | 
			
		||||
import net.minecraft.util.ChatAllowedCharacters;
 | 
			
		||||
import org.lwjgl.input.Keyboard;
 | 
			
		||||
import org.lwjgl.input.Mouse;
 | 
			
		||||
import net.minecraft.client.gui.IGuiEventListener;
 | 
			
		||||
import net.minecraft.client.renderer.BufferBuilder;
 | 
			
		||||
import net.minecraft.client.renderer.Tessellator;
 | 
			
		||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
 | 
			
		||||
import net.minecraft.util.SharedConstants;
 | 
			
		||||
import org.lwjgl.glfw.GLFW;
 | 
			
		||||
import org.lwjgl.opengl.GL11;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.BitSet;
 | 
			
		||||
import java.util.function.Supplier;
 | 
			
		||||
 | 
			
		||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.BACKGROUND;
 | 
			
		||||
 | 
			
		||||
public class WidgetTerminal extends Widget
 | 
			
		||||
public class WidgetTerminal implements IGuiEventListener
 | 
			
		||||
{
 | 
			
		||||
    private static final float TERMINATE_TIME = 0.5f;
 | 
			
		||||
 | 
			
		||||
    private final IComputerContainer m_computer;
 | 
			
		||||
    private final Minecraft client;
 | 
			
		||||
 | 
			
		||||
    private float m_terminateTimer;
 | 
			
		||||
    private float m_rebootTimer;
 | 
			
		||||
    private float m_shutdownTimer;
 | 
			
		||||
    private boolean focused;
 | 
			
		||||
 | 
			
		||||
    private int m_lastClickButton;
 | 
			
		||||
    private int m_lastClickX;
 | 
			
		||||
    private int m_lastClickY;
 | 
			
		||||
    private final Supplier<ClientComputer> computer;
 | 
			
		||||
    private final int termWidth;
 | 
			
		||||
    private final int termHeight;
 | 
			
		||||
 | 
			
		||||
    private boolean m_focus;
 | 
			
		||||
    private boolean m_allowFocusLoss;
 | 
			
		||||
    private float terminateTimer = -1;
 | 
			
		||||
    private float rebootTimer = -1;
 | 
			
		||||
    private float shutdownTimer = -1;
 | 
			
		||||
 | 
			
		||||
    private int m_leftMargin;
 | 
			
		||||
    private int m_rightMargin;
 | 
			
		||||
    private int m_topMargin;
 | 
			
		||||
    private int m_bottomMargin;
 | 
			
		||||
    private int lastMouseButton = -1;
 | 
			
		||||
    private int lastMouseX = -1;
 | 
			
		||||
    private int lastMouseY = -1;
 | 
			
		||||
 | 
			
		||||
    private ArrayList<Integer> m_keysDown;
 | 
			
		||||
    private final int leftMargin;
 | 
			
		||||
    private final int rightMargin;
 | 
			
		||||
    private final int topMargin;
 | 
			
		||||
    private final int bottomMargin;
 | 
			
		||||
 | 
			
		||||
    public WidgetTerminal( int x, int y, int termWidth, int termHeight, IComputerContainer computer, int leftMargin, int rightMargin, int topMargin, int bottomMargin )
 | 
			
		||||
    private final BitSet keysDown = new BitSet( 256 );
 | 
			
		||||
 | 
			
		||||
    public WidgetTerminal( Minecraft client, Supplier<ClientComputer> computer, int termWidth, int termHeight, int leftMargin, int rightMargin, int topMargin, int bottomMargin )
 | 
			
		||||
    {
 | 
			
		||||
        super(
 | 
			
		||||
            x, y,
 | 
			
		||||
            leftMargin + rightMargin + termWidth * FixedWidthFontRenderer.FONT_WIDTH,
 | 
			
		||||
            topMargin + bottomMargin + termHeight * FixedWidthFontRenderer.FONT_HEIGHT
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        m_computer = computer;
 | 
			
		||||
        m_terminateTimer = 0.0f;
 | 
			
		||||
        m_rebootTimer = 0.0f;
 | 
			
		||||
        m_shutdownTimer = 0.0f;
 | 
			
		||||
 | 
			
		||||
        m_lastClickButton = -1;
 | 
			
		||||
        m_lastClickX = -1;
 | 
			
		||||
        m_lastClickY = -1;
 | 
			
		||||
 | 
			
		||||
        m_focus = false;
 | 
			
		||||
        m_allowFocusLoss = true;
 | 
			
		||||
 | 
			
		||||
        m_leftMargin = leftMargin;
 | 
			
		||||
        m_rightMargin = rightMargin;
 | 
			
		||||
        m_topMargin = topMargin;
 | 
			
		||||
        m_bottomMargin = bottomMargin;
 | 
			
		||||
 | 
			
		||||
        m_keysDown = new ArrayList<>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAllowFocusLoss( boolean allowFocusLoss )
 | 
			
		||||
    {
 | 
			
		||||
        m_allowFocusLoss = allowFocusLoss;
 | 
			
		||||
        m_focus = m_focus || !allowFocusLoss;
 | 
			
		||||
        this.client = client;
 | 
			
		||||
        this.computer = computer;
 | 
			
		||||
        this.termWidth = termWidth;
 | 
			
		||||
        this.termHeight = termHeight;
 | 
			
		||||
        this.leftMargin = leftMargin;
 | 
			
		||||
        this.rightMargin = rightMargin;
 | 
			
		||||
        this.topMargin = topMargin;
 | 
			
		||||
        this.bottomMargin = bottomMargin;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onKeyTyped( char ch, int key )
 | 
			
		||||
    public boolean charTyped( char ch, int modifiers )
 | 
			
		||||
    {
 | 
			
		||||
        if( m_focus )
 | 
			
		||||
        if( ch >= 32 && ch <= 126 || ch >= 160 && ch <= 255 ) // printable chars in byte range
 | 
			
		||||
        {
 | 
			
		||||
            // Queue the "char" event
 | 
			
		||||
            queueEvent( "char", Character.toString( ch ) );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean keyPressed( int key, int scancode, int modifiers )
 | 
			
		||||
    {
 | 
			
		||||
        if( key == GLFW.GLFW_KEY_ESCAPE ) return false;
 | 
			
		||||
        if( (modifiers & GLFW.GLFW_MOD_CONTROL) != 0 )
 | 
			
		||||
        {
 | 
			
		||||
            switch( key )
 | 
			
		||||
            {
 | 
			
		||||
                case GLFW.GLFW_KEY_T:
 | 
			
		||||
                    if( terminateTimer < 0 ) terminateTimer = 0;
 | 
			
		||||
                    return true;
 | 
			
		||||
                case GLFW.GLFW_KEY_S:
 | 
			
		||||
                    if( shutdownTimer < 0 ) shutdownTimer = 0;
 | 
			
		||||
                    return true;
 | 
			
		||||
                case GLFW.GLFW_KEY_R:
 | 
			
		||||
                    if( rebootTimer < 0 ) rebootTimer = 0;
 | 
			
		||||
                    return true;
 | 
			
		||||
 | 
			
		||||
                case GLFW.GLFW_KEY_V:
 | 
			
		||||
                    // Ctrl+V for paste
 | 
			
		||||
            if( ch == 22 )
 | 
			
		||||
            {
 | 
			
		||||
                String clipboard = GuiScreen.getClipboardString();
 | 
			
		||||
                    String clipboard = client.keyboardListener.getClipboardString();
 | 
			
		||||
                    if( clipboard != null )
 | 
			
		||||
                    {
 | 
			
		||||
                    // Clip to the first occurance of \r or \n
 | 
			
		||||
                        // Clip to the first occurrence of \r or \n
 | 
			
		||||
                        int newLineIndex1 = clipboard.indexOf( "\r" );
 | 
			
		||||
                        int newLineIndex2 = clipboard.indexOf( "\n" );
 | 
			
		||||
                        if( newLineIndex1 >= 0 && newLineIndex2 >= 0 )
 | 
			
		||||
@@ -111,54 +119,132 @@ public class WidgetTerminal extends Widget
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        // Filter the string
 | 
			
		||||
                    clipboard = ChatAllowedCharacters.filterAllowedCharacters( clipboard );
 | 
			
		||||
 | 
			
		||||
                        clipboard = SharedConstants.filterAllowedCharacters( clipboard );
 | 
			
		||||
                        if( !clipboard.isEmpty() )
 | 
			
		||||
                        {
 | 
			
		||||
                        // Clip to 512 characters
 | 
			
		||||
                        if( clipboard.length() > 512 )
 | 
			
		||||
                        {
 | 
			
		||||
                            clipboard = clipboard.substring( 0, 512 );
 | 
			
		||||
                            // Clip to 512 characters and queue the event
 | 
			
		||||
                            if( clipboard.length() > 512 ) clipboard = clipboard.substring( 0, 512 );
 | 
			
		||||
                            queueEvent( "paste", clipboard );
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        // Queue the "paste" event
 | 
			
		||||
                        queueEvent( "paste", new Object[] {
 | 
			
		||||
                            clipboard
 | 
			
		||||
                        } );
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if( key >= 0 && terminateTimer < 0 && rebootTimer < 0 && shutdownTimer < 0 )
 | 
			
		||||
        {
 | 
			
		||||
            // Queue the "key" event and add to the down set
 | 
			
		||||
            boolean repeat = keysDown.get( key );
 | 
			
		||||
            keysDown.set( key );
 | 
			
		||||
            IComputer computer = this.computer.get();
 | 
			
		||||
            if( computer != null ) computer.keyDown( key, repeat );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
            // Regular keys normally
 | 
			
		||||
            if( m_terminateTimer <= 0.0f && m_rebootTimer <= 0.0f && m_shutdownTimer <= 0.0f )
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean keyReleased( int key, int scancode, int modifiers )
 | 
			
		||||
    {
 | 
			
		||||
                boolean repeat = Keyboard.isRepeatEvent();
 | 
			
		||||
                boolean handled = false;
 | 
			
		||||
                if( key > 0 )
 | 
			
		||||
        // Queue the "key_up" event and remove from the down set
 | 
			
		||||
        if( key >= 0 && keysDown.get( key ) )
 | 
			
		||||
        {
 | 
			
		||||
                    if( !repeat )
 | 
			
		||||
                    {
 | 
			
		||||
                        m_keysDown.add( key );
 | 
			
		||||
            keysDown.set( key, false );
 | 
			
		||||
            IComputer computer = this.computer.get();
 | 
			
		||||
            if( computer != null ) computer.keyUp( key );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
                    // Queue the "key" event
 | 
			
		||||
                    queueEvent( "key", new Object[] {
 | 
			
		||||
                        key, repeat
 | 
			
		||||
                    } );
 | 
			
		||||
                    handled = true;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if( (ch >= 32 && ch <= 126) || (ch >= 160 && ch <= 255) ) // printable chars in byte range
 | 
			
		||||
        switch( key )
 | 
			
		||||
        {
 | 
			
		||||
                    // Queue the "char" event
 | 
			
		||||
                    queueEvent( "char", new Object[] {
 | 
			
		||||
                        Character.toString( ch )
 | 
			
		||||
                    } );
 | 
			
		||||
                    handled = true;
 | 
			
		||||
            case GLFW.GLFW_KEY_T:
 | 
			
		||||
                terminateTimer = -1;
 | 
			
		||||
                break;
 | 
			
		||||
            case GLFW.GLFW_KEY_R:
 | 
			
		||||
                rebootTimer = -1;
 | 
			
		||||
                break;
 | 
			
		||||
            case GLFW.GLFW_KEY_S:
 | 
			
		||||
                shutdownTimer = -1;
 | 
			
		||||
                break;
 | 
			
		||||
            case GLFW.GLFW_KEY_LEFT_CONTROL:
 | 
			
		||||
            case GLFW.GLFW_KEY_RIGHT_CONTROL:
 | 
			
		||||
                terminateTimer = rebootTimer = shutdownTimer = -1;
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
                return handled;
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean mouseClicked( double mouseX, double mouseY, int button )
 | 
			
		||||
    {
 | 
			
		||||
        ClientComputer computer = this.computer.get();
 | 
			
		||||
        if( computer == null || !computer.isColour() || button < 0 || button > 2 ) return false;
 | 
			
		||||
 | 
			
		||||
        Terminal term = computer.getTerminal();
 | 
			
		||||
        if( term != null )
 | 
			
		||||
        {
 | 
			
		||||
            int charX = (int) (mouseX / FixedWidthFontRenderer.FONT_WIDTH);
 | 
			
		||||
            int charY = (int) (mouseY / FixedWidthFontRenderer.FONT_HEIGHT);
 | 
			
		||||
            charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
 | 
			
		||||
            charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
 | 
			
		||||
 | 
			
		||||
            computer.mouseClick( button + 1, charX + 1, charY + 1 );
 | 
			
		||||
 | 
			
		||||
            lastMouseButton = button;
 | 
			
		||||
            lastMouseX = charX;
 | 
			
		||||
            lastMouseY = charY;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean mouseReleased( double mouseX, double mouseY, int button )
 | 
			
		||||
    {
 | 
			
		||||
        ClientComputer computer = this.computer.get();
 | 
			
		||||
        if( computer == null || !computer.isColour() || button < 0 || button > 2 ) return false;
 | 
			
		||||
 | 
			
		||||
        Terminal term = computer.getTerminal();
 | 
			
		||||
        if( term != null )
 | 
			
		||||
        {
 | 
			
		||||
            int charX = (int) (mouseX / FixedWidthFontRenderer.FONT_WIDTH);
 | 
			
		||||
            int charY = (int) (mouseY / FixedWidthFontRenderer.FONT_HEIGHT);
 | 
			
		||||
            charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
 | 
			
		||||
            charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
 | 
			
		||||
 | 
			
		||||
            if( lastMouseButton == button )
 | 
			
		||||
            {
 | 
			
		||||
                computer.mouseUp( lastMouseButton + 1, charX + 1, charY + 1 );
 | 
			
		||||
                lastMouseButton = -1;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            lastMouseX = charX;
 | 
			
		||||
            lastMouseY = charY;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean mouseDragged( double mouseX, double mouseY, int button, double v2, double v3 )
 | 
			
		||||
    {
 | 
			
		||||
        ClientComputer computer = this.computer.get();
 | 
			
		||||
        if( computer == null || !computer.isColour() || button < 0 || button > 2 ) return false;
 | 
			
		||||
 | 
			
		||||
        Terminal term = computer.getTerminal();
 | 
			
		||||
        if( term != null )
 | 
			
		||||
        {
 | 
			
		||||
            int charX = (int) (mouseX / FixedWidthFontRenderer.FONT_WIDTH);
 | 
			
		||||
            int charY = (int) (mouseY / FixedWidthFontRenderer.FONT_HEIGHT);
 | 
			
		||||
            charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
 | 
			
		||||
            charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
 | 
			
		||||
 | 
			
		||||
            if( button == lastMouseButton && (charX != lastMouseX || charY != lastMouseY) )
 | 
			
		||||
            {
 | 
			
		||||
                computer.mouseDrag( button + 1, charX + 1, charY + 1 );
 | 
			
		||||
                lastMouseX = charX;
 | 
			
		||||
                lastMouseY = charY;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -166,255 +252,120 @@ public class WidgetTerminal extends Widget
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void mouseClicked( int mouseX, int mouseY, int button )
 | 
			
		||||
    public boolean mouseScrolled( double mouseX, double mouseY, double delta )
 | 
			
		||||
    {
 | 
			
		||||
        if( mouseX >= getXPosition() && mouseX < getXPosition() + getWidth() &&
 | 
			
		||||
            mouseY >= getYPosition() && mouseY < getYPosition() + getHeight() )
 | 
			
		||||
        {
 | 
			
		||||
            if( !m_focus && button == 0 )
 | 
			
		||||
            {
 | 
			
		||||
                m_focus = true;
 | 
			
		||||
            }
 | 
			
		||||
        ClientComputer computer = this.computer.get();
 | 
			
		||||
        if( computer == null || !computer.isColour() || delta == 0 ) return false;
 | 
			
		||||
 | 
			
		||||
            if( m_focus )
 | 
			
		||||
            {
 | 
			
		||||
                IComputer computer = m_computer.getComputer();
 | 
			
		||||
                if( computer != null && computer.isColour() && button >= 0 && button <= 2 )
 | 
			
		||||
                {
 | 
			
		||||
        Terminal term = computer.getTerminal();
 | 
			
		||||
        if( term != null )
 | 
			
		||||
        {
 | 
			
		||||
                        int charX = (mouseX - (getXPosition() + m_leftMargin)) / FixedWidthFontRenderer.FONT_WIDTH;
 | 
			
		||||
                        int charY = (mouseY - (getYPosition() + m_topMargin)) / FixedWidthFontRenderer.FONT_HEIGHT;
 | 
			
		||||
            int charX = (int) (mouseX / FixedWidthFontRenderer.FONT_WIDTH);
 | 
			
		||||
            int charY = (int) (mouseY / FixedWidthFontRenderer.FONT_HEIGHT);
 | 
			
		||||
            charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
 | 
			
		||||
            charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
 | 
			
		||||
 | 
			
		||||
                        computer.queueEvent( "mouse_click", new Object[] {
 | 
			
		||||
                            button + 1, charX + 1, charY + 1
 | 
			
		||||
                        } );
 | 
			
		||||
            computer.mouseScroll( delta < 0 ? 1 : -1, charX + 1, charY + 1 );
 | 
			
		||||
 | 
			
		||||
                        m_lastClickButton = button;
 | 
			
		||||
                        m_lastClickX = charX;
 | 
			
		||||
                        m_lastClickY = charY;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            if( m_focus && button == 0 && m_allowFocusLoss )
 | 
			
		||||
            {
 | 
			
		||||
                m_focus = false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
            lastMouseX = charX;
 | 
			
		||||
            lastMouseY = charY;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onKeyboardInput()
 | 
			
		||||
    {
 | 
			
		||||
        boolean handled = false;
 | 
			
		||||
        for( int i = m_keysDown.size() - 1; i >= 0; --i )
 | 
			
		||||
        {
 | 
			
		||||
            int key = m_keysDown.get( i );
 | 
			
		||||
            if( !Keyboard.isKeyDown( key ) )
 | 
			
		||||
            {
 | 
			
		||||
                m_keysDown.remove( i );
 | 
			
		||||
                if( m_focus )
 | 
			
		||||
                {
 | 
			
		||||
                    // Queue the "key_up" event
 | 
			
		||||
                    queueEvent( "key_up", new Object[] {
 | 
			
		||||
                        key
 | 
			
		||||
                    } );
 | 
			
		||||
                    handled = true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        return handled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void handleMouseInput( int mouseX, int mouseY )
 | 
			
		||||
    {
 | 
			
		||||
        IComputer computer = m_computer.getComputer();
 | 
			
		||||
        if( mouseX >= getXPosition() && mouseX < getXPosition() + getWidth() &&
 | 
			
		||||
            mouseY >= getYPosition() && mouseY < getYPosition() + getHeight() &&
 | 
			
		||||
            computer != null && computer.isColour() )
 | 
			
		||||
        {
 | 
			
		||||
            Terminal term = computer.getTerminal();
 | 
			
		||||
            if( term != null )
 | 
			
		||||
            {
 | 
			
		||||
                int charX = (mouseX - (getXPosition() + m_leftMargin)) / FixedWidthFontRenderer.FONT_WIDTH;
 | 
			
		||||
                int charY = (mouseY - (getYPosition() + m_topMargin)) / FixedWidthFontRenderer.FONT_HEIGHT;
 | 
			
		||||
                charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
 | 
			
		||||
                charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
 | 
			
		||||
 | 
			
		||||
                if( m_lastClickButton >= 0 && !Mouse.isButtonDown( m_lastClickButton ) )
 | 
			
		||||
                {
 | 
			
		||||
                    if( m_focus )
 | 
			
		||||
                    {
 | 
			
		||||
                        computer.queueEvent( "mouse_up", new Object[] {
 | 
			
		||||
                            m_lastClickButton + 1, charX + 1, charY + 1
 | 
			
		||||
                        } );
 | 
			
		||||
                    }
 | 
			
		||||
                    m_lastClickButton = -1;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                int wheelChange = Mouse.getEventDWheel();
 | 
			
		||||
                if( wheelChange == 0 && m_lastClickButton == -1 )
 | 
			
		||||
                {
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if( m_focus )
 | 
			
		||||
                {
 | 
			
		||||
                    if( wheelChange < 0 )
 | 
			
		||||
                    {
 | 
			
		||||
                        computer.queueEvent( "mouse_scroll", new Object[] {
 | 
			
		||||
                            1, charX + 1, charY + 1
 | 
			
		||||
                        } );
 | 
			
		||||
                    }
 | 
			
		||||
                    else if( wheelChange > 0 )
 | 
			
		||||
                    {
 | 
			
		||||
                        computer.queueEvent( "mouse_scroll", new Object[] {
 | 
			
		||||
                            -1, charX + 1, charY + 1
 | 
			
		||||
                        } );
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    if( m_lastClickButton >= 0 && (charX != m_lastClickX || charY != m_lastClickY) )
 | 
			
		||||
                    {
 | 
			
		||||
                        computer.queueEvent( "mouse_drag", new Object[] {
 | 
			
		||||
                            m_lastClickButton + 1, charX + 1, charY + 1
 | 
			
		||||
                        } );
 | 
			
		||||
                        m_lastClickX = charX;
 | 
			
		||||
                        m_lastClickY = charY;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void update()
 | 
			
		||||
    {
 | 
			
		||||
        // Handle special keys
 | 
			
		||||
        if( m_focus && (Keyboard.isKeyDown( 29 ) || Keyboard.isKeyDown( 157 )) )
 | 
			
		||||
        {
 | 
			
		||||
            // Ctrl+T for terminate
 | 
			
		||||
            if( Keyboard.isKeyDown( 20 ) )
 | 
			
		||||
            {
 | 
			
		||||
                if( m_terminateTimer < TERMINATE_TIME )
 | 
			
		||||
                {
 | 
			
		||||
                    m_terminateTimer = m_terminateTimer + 0.05f;
 | 
			
		||||
                    if( m_terminateTimer >= TERMINATE_TIME )
 | 
			
		||||
        if( terminateTimer >= 0 && terminateTimer < TERMINATE_TIME && (terminateTimer += 0.05f) > TERMINATE_TIME )
 | 
			
		||||
        {
 | 
			
		||||
            queueEvent( "terminate" );
 | 
			
		||||
        }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
 | 
			
		||||
        if( shutdownTimer >= 0 && shutdownTimer < TERMINATE_TIME && (shutdownTimer += 0.05f) > TERMINATE_TIME )
 | 
			
		||||
        {
 | 
			
		||||
                m_terminateTimer = 0.0f;
 | 
			
		||||
            ClientComputer computer = this.computer.get();
 | 
			
		||||
            if( computer != null ) computer.shutdown();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
            // Ctrl+R for reboot
 | 
			
		||||
            if( Keyboard.isKeyDown( 19 ) )
 | 
			
		||||
        if( rebootTimer >= 0 && rebootTimer < TERMINATE_TIME && (rebootTimer += 0.05f) > TERMINATE_TIME )
 | 
			
		||||
        {
 | 
			
		||||
                if( m_rebootTimer < TERMINATE_TIME )
 | 
			
		||||
                {
 | 
			
		||||
                    m_rebootTimer = m_rebootTimer + 0.05f;
 | 
			
		||||
                    if( m_rebootTimer >= TERMINATE_TIME )
 | 
			
		||||
                    {
 | 
			
		||||
                        IComputer computer = m_computer.getComputer();
 | 
			
		||||
                        if( computer != null )
 | 
			
		||||
                        {
 | 
			
		||||
                            computer.reboot();
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                m_rebootTimer = 0.0f;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Ctrl+S for shutdown
 | 
			
		||||
            if( Keyboard.isKeyDown( 31 ) )
 | 
			
		||||
            {
 | 
			
		||||
                if( m_shutdownTimer < TERMINATE_TIME )
 | 
			
		||||
                {
 | 
			
		||||
                    m_shutdownTimer = m_shutdownTimer + 0.05f;
 | 
			
		||||
                    if( m_shutdownTimer >= TERMINATE_TIME )
 | 
			
		||||
                    {
 | 
			
		||||
                        IComputer computer = m_computer.getComputer();
 | 
			
		||||
                        if( computer != null )
 | 
			
		||||
                        {
 | 
			
		||||
                            computer.shutdown();
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                m_shutdownTimer = 0.0f;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            m_terminateTimer = 0.0f;
 | 
			
		||||
            m_rebootTimer = 0.0f;
 | 
			
		||||
            m_shutdownTimer = 0.0f;
 | 
			
		||||
            ClientComputer computer = this.computer.get();
 | 
			
		||||
            if( computer != null ) computer.reboot();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void draw( Minecraft mc, int xOrigin, int yOrigin, int mouseX, int mouseY )
 | 
			
		||||
    public boolean changeFocus( boolean reversed )
 | 
			
		||||
    {
 | 
			
		||||
        int startX = xOrigin + getXPosition();
 | 
			
		||||
        int startY = yOrigin + getYPosition();
 | 
			
		||||
        if( focused )
 | 
			
		||||
        {
 | 
			
		||||
            // When blurring, we should make all keys go up
 | 
			
		||||
            for( int key = 0; key < keysDown.size(); key++ )
 | 
			
		||||
            {
 | 
			
		||||
                if( keysDown.get( key ) ) queueEvent( "key_up", key );
 | 
			
		||||
            }
 | 
			
		||||
            keysDown.clear();
 | 
			
		||||
 | 
			
		||||
        synchronized( m_computer )
 | 
			
		||||
            // When blurring, we should make the last mouse button go up
 | 
			
		||||
            if( lastMouseButton > 0 )
 | 
			
		||||
            {
 | 
			
		||||
                IComputer computer = this.computer.get();
 | 
			
		||||
                if( computer != null ) computer.mouseUp( lastMouseButton + 1, lastMouseX + 1, lastMouseY + 1 );
 | 
			
		||||
                lastMouseButton = -1;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            shutdownTimer = terminateTimer = rebootTimer = -1;
 | 
			
		||||
        }
 | 
			
		||||
        focused = !focused;
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void draw( int originX, int originY )
 | 
			
		||||
    {
 | 
			
		||||
        synchronized( computer )
 | 
			
		||||
        {
 | 
			
		||||
            // Draw the screen contents
 | 
			
		||||
            IComputer computer = m_computer.getComputer();
 | 
			
		||||
            Terminal terminal = (computer != null) ? computer.getTerminal() : null;
 | 
			
		||||
            ClientComputer computer = this.computer.get();
 | 
			
		||||
            Terminal terminal = computer != null ? computer.getTerminal() : null;
 | 
			
		||||
            if( terminal != null )
 | 
			
		||||
            {
 | 
			
		||||
                // Draw the terminal
 | 
			
		||||
                boolean greyscale = !computer.isColour();
 | 
			
		||||
 | 
			
		||||
                Palette palette = terminal.getPalette();
 | 
			
		||||
 | 
			
		||||
                // Get the data from the terminal first
 | 
			
		||||
                // Unfortunately we have to keep the lock for the whole of drawing, so the text doesn't change under us.
 | 
			
		||||
                FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
 | 
			
		||||
                boolean tblink = m_focus && terminal.getCursorBlink() && FrameInfo.getGlobalCursorBlink();
 | 
			
		||||
                boolean tblink = terminal.getCursorBlink() && FrameInfo.getGlobalCursorBlink();
 | 
			
		||||
                int tw = terminal.getWidth();
 | 
			
		||||
                int th = terminal.getHeight();
 | 
			
		||||
                int tx = terminal.getCursorX();
 | 
			
		||||
                int ty = terminal.getCursorY();
 | 
			
		||||
 | 
			
		||||
                int x = startX + m_leftMargin;
 | 
			
		||||
                int y = startY + m_topMargin;
 | 
			
		||||
 | 
			
		||||
                // Draw margins
 | 
			
		||||
                TextBuffer emptyLine = new TextBuffer( ' ', tw );
 | 
			
		||||
                if( m_topMargin > 0 )
 | 
			
		||||
                if( topMargin > 0 )
 | 
			
		||||
                {
 | 
			
		||||
                    fontRenderer.drawString( emptyLine, x, startY, terminal.getTextColourLine( 0 ), terminal.getBackgroundColourLine( 0 ), m_leftMargin, m_rightMargin, greyscale, palette );
 | 
			
		||||
                    fontRenderer.drawString( emptyLine, originX, originY - topMargin,
 | 
			
		||||
                        terminal.getTextColourLine( 0 ), terminal.getBackgroundColourLine( 0 ),
 | 
			
		||||
                        leftMargin, rightMargin, greyscale, palette );
 | 
			
		||||
                }
 | 
			
		||||
                if( m_bottomMargin > 0 )
 | 
			
		||||
 | 
			
		||||
                if( bottomMargin > 0 )
 | 
			
		||||
                {
 | 
			
		||||
                    fontRenderer.drawString( emptyLine, x, startY + 2 * m_bottomMargin + (th - 1) * FixedWidthFontRenderer.FONT_HEIGHT, terminal.getTextColourLine( th - 1 ), terminal.getBackgroundColourLine( th - 1 ), m_leftMargin, m_rightMargin, greyscale, palette );
 | 
			
		||||
                    fontRenderer.drawString( emptyLine, originX, originY + bottomMargin + (th - 1) * FixedWidthFontRenderer.FONT_HEIGHT,
 | 
			
		||||
                        terminal.getTextColourLine( th - 1 ), terminal.getBackgroundColourLine( th - 1 ),
 | 
			
		||||
                        leftMargin, rightMargin, greyscale, palette );
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Draw lines
 | 
			
		||||
                int y = originY;
 | 
			
		||||
                for( int line = 0; line < th; line++ )
 | 
			
		||||
                {
 | 
			
		||||
                    TextBuffer text = terminal.getLine( line );
 | 
			
		||||
                    TextBuffer colour = terminal.getTextColourLine( line );
 | 
			
		||||
                    TextBuffer backgroundColour = terminal.getBackgroundColourLine( line );
 | 
			
		||||
                    fontRenderer.drawString( text, x, y, colour, backgroundColour, m_leftMargin, m_rightMargin, greyscale, palette );
 | 
			
		||||
                    fontRenderer.drawString( text, originX, y, colour, backgroundColour, leftMargin, rightMargin, greyscale, palette );
 | 
			
		||||
                    y += FixedWidthFontRenderer.FONT_HEIGHT;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@@ -425,8 +376,8 @@ public class WidgetTerminal extends Widget
 | 
			
		||||
 | 
			
		||||
                    fontRenderer.drawString(
 | 
			
		||||
                        cursor,
 | 
			
		||||
                        x + FixedWidthFontRenderer.FONT_WIDTH * tx,
 | 
			
		||||
                        startY + m_topMargin + FixedWidthFontRenderer.FONT_HEIGHT * ty,
 | 
			
		||||
                        originX + FixedWidthFontRenderer.FONT_WIDTH * tx,
 | 
			
		||||
                        originY + FixedWidthFontRenderer.FONT_HEIGHT * ty,
 | 
			
		||||
                        cursorColour, null,
 | 
			
		||||
                        0, 0,
 | 
			
		||||
                        greyscale,
 | 
			
		||||
@@ -437,16 +388,29 @@ public class WidgetTerminal extends Widget
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                // Draw a black background
 | 
			
		||||
                mc.getTextureManager().bindTexture( BACKGROUND );
 | 
			
		||||
                Colour black = Colour.Black;
 | 
			
		||||
                GlStateManager.color( black.getR(), black.getG(), black.getB(), 1.0f );
 | 
			
		||||
                GlStateManager.color4f( black.getR(), black.getG(), black.getB(), 1.0f );
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    drawTexturedModalRect( startX, startY, 0, 0, getWidth(), getHeight() );
 | 
			
		||||
                    int x = originX - leftMargin;
 | 
			
		||||
                    int y = originY - rightMargin;
 | 
			
		||||
                    int width = termWidth * FixedWidthFontRenderer.FONT_WIDTH + leftMargin + rightMargin;
 | 
			
		||||
                    int height = termHeight * FixedWidthFontRenderer.FONT_HEIGHT + topMargin + bottomMargin;
 | 
			
		||||
 | 
			
		||||
                    client.getTextureManager().bindTexture( BACKGROUND );
 | 
			
		||||
 | 
			
		||||
                    Tessellator tesslector = Tessellator.getInstance();
 | 
			
		||||
                    BufferBuilder buffer = tesslector.getBuffer();
 | 
			
		||||
                    buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX );
 | 
			
		||||
                    buffer.pos( x, y + height, 0 ).tex( 0 / 256.0, height / 256.0 ).endVertex();
 | 
			
		||||
                    buffer.pos( x + width, y + height, 0 ).tex( width / 256.0, height / 256.0 ).endVertex();
 | 
			
		||||
                    buffer.pos( x + width, y, 0 ).tex( width / 256.0, 0 / 256.0 ).endVertex();
 | 
			
		||||
                    buffer.pos( x, y, 0 ).tex( 0 / 256.0, 0 / 256.0 ).endVertex();
 | 
			
		||||
                    tesslector.draw();
 | 
			
		||||
                }
 | 
			
		||||
                finally
 | 
			
		||||
                {
 | 
			
		||||
                    GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
 | 
			
		||||
                    GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -454,19 +418,19 @@ public class WidgetTerminal extends Widget
 | 
			
		||||
 | 
			
		||||
    private void queueEvent( String event )
 | 
			
		||||
    {
 | 
			
		||||
        IComputer computer = m_computer.getComputer();
 | 
			
		||||
        if( computer != null )
 | 
			
		||||
        {
 | 
			
		||||
            computer.queueEvent( event );
 | 
			
		||||
        }
 | 
			
		||||
        ClientComputer computer = this.computer.get();
 | 
			
		||||
        if( computer != null ) computer.queueEvent( event );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void queueEvent( String event, Object[] args )
 | 
			
		||||
    private void queueEvent( String event, Object... args )
 | 
			
		||||
    {
 | 
			
		||||
        IComputer computer = m_computer.getComputer();
 | 
			
		||||
        if( computer != null )
 | 
			
		||||
        ClientComputer computer = this.computer.get();
 | 
			
		||||
        if( computer != null ) computer.queueEvent( event, args );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isMouseOver( double x, double y )
 | 
			
		||||
    {
 | 
			
		||||
            computer.queueEvent( event, args );
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,105 @@
 | 
			
		||||
/*
 | 
			
		||||
 * This file is part of ComputerCraft - http://www.computercraft.info
 | 
			
		||||
 * Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
 | 
			
		||||
 * Send enquiries to dratcliffe@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
package dan200.computercraft.client.gui.widgets;
 | 
			
		||||
 | 
			
		||||
import net.minecraft.client.gui.IGuiEventListener;
 | 
			
		||||
 | 
			
		||||
public class WidgetWrapper implements IGuiEventListener
 | 
			
		||||
{
 | 
			
		||||
    private final IGuiEventListener listener;
 | 
			
		||||
    private final int x;
 | 
			
		||||
    private final int y;
 | 
			
		||||
    private final int width;
 | 
			
		||||
    private final int height;
 | 
			
		||||
 | 
			
		||||
    public WidgetWrapper( IGuiEventListener listener, int x, int y, int width, int height )
 | 
			
		||||
    {
 | 
			
		||||
        this.listener = listener;
 | 
			
		||||
        this.x = x;
 | 
			
		||||
        this.y = y;
 | 
			
		||||
        this.width = width;
 | 
			
		||||
        this.height = height;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean changeFocus( boolean b )
 | 
			
		||||
    {
 | 
			
		||||
        return listener.changeFocus( b );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean mouseClicked( double x, double y, int button )
 | 
			
		||||
    {
 | 
			
		||||
        double dx = x - this.x, dy = y - this.y;
 | 
			
		||||
        return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseClicked( dx, dy, button );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean mouseReleased( double x, double y, int button )
 | 
			
		||||
    {
 | 
			
		||||
        double dx = x - this.x, dy = y - this.y;
 | 
			
		||||
        return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseReleased( dx, dy, button );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY )
 | 
			
		||||
    {
 | 
			
		||||
        double dx = x - this.x, dy = y - this.y;
 | 
			
		||||
        return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseDragged( dx, dy, button, deltaX, deltaY );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean mouseScrolled( double x, double y, double delta )
 | 
			
		||||
    {
 | 
			
		||||
        double dx = x - this.x, dy = y - this.y;
 | 
			
		||||
        return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseScrolled( dx, dy, delta );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean keyPressed( int key, int scancode, int modifiers )
 | 
			
		||||
    {
 | 
			
		||||
        return listener.keyPressed( key, scancode, modifiers );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean keyReleased( int key, int scancode, int modifiers )
 | 
			
		||||
    {
 | 
			
		||||
        return listener.keyReleased( key, scancode, modifiers );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean charTyped( char character, int modifiers )
 | 
			
		||||
    {
 | 
			
		||||
        return listener.charTyped( character, modifiers );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getX()
 | 
			
		||||
    {
 | 
			
		||||
        return x;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getY()
 | 
			
		||||
    {
 | 
			
		||||
        return y;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getWidth()
 | 
			
		||||
    {
 | 
			
		||||
        return width;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getHeight()
 | 
			
		||||
    {
 | 
			
		||||
        return height;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isMouseOver( double x, double y )
 | 
			
		||||
    {
 | 
			
		||||
        double dx = x - this.x, dy = y - this.y;
 | 
			
		||||
        return dx >= 0 && dx < width && dy >= 0 && dy < height;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user