├── .gitattributes ├── LICENSE ├── README.md ├── data ├── minecraft │ └── tags │ │ └── functions │ │ ├── load.json │ │ └── tick.json └── wasd │ ├── functions │ ├── demos │ │ ├── onno_compare.mcfunction │ │ ├── print_subtitle_mounted.mcfunction │ │ └── print_subtitle_walking.mcfunction │ ├── init.mcfunction │ ├── main.mcfunction │ ├── mounted.mcfunction │ ├── walking.mcfunction │ └── zprivate │ │ ├── apply_tags.mcfunction │ │ ├── atan2.mcfunction │ │ ├── calc_range.mcfunction │ │ └── input.mcfunction │ └── predicates │ ├── is_mounted.json │ └── is_wasder.json └── pack.mcmeta /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WASD Detection 2 | 3 | [![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-) 4 | [![Discord](https://img.shields.io/badge/Discord-⛓-blue.svg)](https://discord.gg/VzjQ7kFKqD) 5 | [![Tutorial](https://img.shields.io/badge/Tutorial-▶-red.svg)](https://www.youtube.com/watch?v=77jQnRSYYss) 6 | [![Downloads](https://img.shields.io/github/downloads/CloudWolfYT/WASD-Detection/total.svg)](https://github.com/CloudWolfYT/WASD-Detection/releases) 7 | 8 | A Minecraft Datapack that detects WASD inputs while mounted or walking! 9 | 10 | 11 | 12 | 14 | 15 | 17 | 18 | 19 | 21 | 22 | 24 | 25 |
Mounted Case (1) relies on function structure using fake players
13 | 1. execute if predicate wasd:is_mounted run function wasd:mounted
Outputs:
1. execute if score .w wasd matches 1 run title @s {"text":"W"}
Mounted Case (2) can be run at any context using tags
1. scoreboard players set in wasd 1
16 | 2. execute as @a if predicate wasd:is_mounted run function wasd:mounted
Outputs:
1. execute as @a[tag=wasd.w] run title @s {"text":"W"}
Walking Case (1) relies on function structure using fake players
20 | 1. function wasd:walking
Outputs:
1. execute if score .w wasd matches 1 run title @s {"text":"W"}
Walking Case (2) can be run at any context using tags
1. scoreboard players set in wasd 1
23 | 2. execute as @a if predicate wasd:is_mounted run function wasd:walking
Outputs:
1. execute as @a[tag=wasd.w] run title @s {"text":"W"}
26 | 27 | By Default a demo command is left in wasd:main which runs a function to show an example use-case in the function "wasd:demo/print_subtitle_mounted" 28 | 29 | ## Contributors 🧱 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |

Cloud Wolf

🔨

The Der Discohund

💡
40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /data/minecraft/tags/functions/load.json: -------------------------------------------------------------------------------- 1 | { 2 | "values":[ 3 | "wasd:init" 4 | ] 5 | } -------------------------------------------------------------------------------- /data/minecraft/tags/functions/tick.json: -------------------------------------------------------------------------------- 1 | { 2 | "values":[ 3 | "wasd:main" 4 | ] 5 | } -------------------------------------------------------------------------------- /data/wasd/functions/demos/onno_compare.mcfunction: -------------------------------------------------------------------------------- 1 | function wasd:detect 2 | function wasd:_wasd/mounted 3 | title @a times 0 10 0 4 | title @a title "" 5 | data remove storage test temp 6 | data remove storage test temp1 7 | execute if score .w wasd matches 1 run data modify storage test temp append value '{"text":"W","color":"green"}' 8 | execute if score .s wasd matches 1 run data modify storage test temp append value '{"text":"S","color":"green"}' 9 | execute if score .a wasd matches 1 run data modify storage test temp append value '{"text":"A","color":"green"}' 10 | execute if score .d wasd matches 1 run data modify storage test temp append value '{"text":"D","color":"green"}' 11 | execute as @a if entity @s[tag=wasd.forward] run data modify storage test temp1 append value '{"text":"W","color":"aqua"}' 12 | execute as @a if entity @s[tag=wasd.backward] run data modify storage test temp1 append value '{"text":"S","color":"aqua"}' 13 | execute as @a if entity @s[tag=wasd.left] run data modify storage test temp1 append value '{"text":"A","color":"aqua"}' 14 | execute as @a if entity @s[tag=wasd.right] run data modify storage test temp1 append value '{"text":"D","color":"aqua"}' 15 | title @a subtitle [{"text":"Mine="},{"nbt":"temp[]","storage":"test","interpret":true,"separator":{"text":""}},{"text":" | Onno="},{"nbt":"temp1[]","storage":"test","interpret":true,"separator":{"text":""}}] -------------------------------------------------------------------------------- /data/wasd/functions/demos/print_subtitle_mounted.mcfunction: -------------------------------------------------------------------------------- 1 | execute if predicate wasd:is_mounted run function wasd:mounted 2 | title @a times 0 10 0 3 | title @a title "" 4 | data remove storage test temp 5 | execute if score .w wasd matches 1 run data modify storage test temp append value '{"text":"W","color":"green"}' 6 | execute if score .s wasd matches 1 run data modify storage test temp append value '{"text":"S","color":"green"}' 7 | execute if score .a wasd matches 1 run data modify storage test temp append value '{"text":"A","color":"green"}' 8 | execute if score .d wasd matches 1 run data modify storage test temp append value '{"text":"D","color":"green"}' 9 | title @a subtitle [{"nbt":"temp[]","storage":"test","interpret":true,"separator":{"text":""}}] -------------------------------------------------------------------------------- /data/wasd/functions/demos/print_subtitle_walking.mcfunction: -------------------------------------------------------------------------------- 1 | function wasd:walking 2 | title @a times 0 10 0 3 | title @a title "" 4 | data remove storage test temp 5 | execute if score .w wasd matches 1 run data modify storage test temp append value '{"text":"W","color":"green"}' 6 | execute if score .s wasd matches 1 run data modify storage test temp append value '{"text":"S","color":"green"}' 7 | execute if score .a wasd matches 1 run data modify storage test temp append value '{"text":"A","color":"green"}' 8 | execute if score .d wasd matches 1 run data modify storage test temp append value '{"text":"D","color":"green"}' 9 | title @a subtitle [{"nbt":"temp[]","storage":"test","interpret":true,"separator":{"text":""}}] -------------------------------------------------------------------------------- /data/wasd/functions/init.mcfunction: -------------------------------------------------------------------------------- 1 | scoreboard objectives add wasd dummy 2 | scoreboard objectives add wasd.x dummy 3 | scoreboard objectives add wasd.z dummy 4 | scoreboard objectives add math dummy 5 | 6 | scoreboard objectives add constant dummy 7 | scoreboard players set #-46496 constant -46496 8 | scoreboard players set #-1 constant -1 9 | scoreboard players set #360 constant 360 10 | scoreboard players set #1000 constant 1000 11 | scoreboard players set #10000 constant 10000 12 | scoreboard players set #57295 constant 57295 13 | scoreboard players set #100000 constant 100000 14 | scoreboard players set #1000000 constant 1000000 15 | -------------------------------------------------------------------------------- /data/wasd/functions/main.mcfunction: -------------------------------------------------------------------------------- 1 | #execute as @a if predicate wasd:is_mounted run function wasd:demos/onno_compare 2 | execute as @a run function wasd:demos/print_subtitle_mounted 3 | #execute as @a run function wasd:demos/print_subtitle_walking -------------------------------------------------------------------------------- /data/wasd/functions/mounted.mcfunction: -------------------------------------------------------------------------------- 1 | data modify storage cw_wasd Motion set from entity @s Motion 2 | execute store result score .x wasd run data get storage cw_wasd Motion[0] 1000.0 3 | execute store result score .z wasd run data get storage cw_wasd Motion[2] 1000.0 4 | function wasd:zprivate/input -------------------------------------------------------------------------------- /data/wasd/functions/walking.mcfunction: -------------------------------------------------------------------------------- 1 | data modify storage cw_wasd Pos set from entity @s Pos 2 | execute store result score .x wasd run data get storage cw_wasd Pos[0] 100.0 3 | execute store result score .z wasd run data get storage cw_wasd Pos[2] 100.0 4 | scoreboard players operation #temp wasd.x = .x wasd 5 | scoreboard players operation #temp wasd.z = .z wasd 6 | scoreboard players operation .x wasd -= @s wasd.x 7 | scoreboard players operation .z wasd -= @s wasd.z 8 | function wasd:zprivate/input 9 | scoreboard players operation @s wasd.x = #temp wasd.x 10 | scoreboard players operation @s wasd.z = #temp wasd.z -------------------------------------------------------------------------------- /data/wasd/functions/zprivate/apply_tags.mcfunction: -------------------------------------------------------------------------------- 1 | ## added functionality for those not utilizing perfect organization 2 | tag @s remove wasd.w 3 | tag @s remove wasd.a 4 | tag @s remove wasd.s 5 | tag @s remove wasd.d 6 | execute if score .w wasd matches 1 run tag @s add wasd.w 7 | execute if score .a wasd matches 1 run tag @s add wasd.a 8 | execute if score .s wasd matches 1 run tag @s add wasd.s 9 | execute if score .d wasd matches 1 run tag @s add wasd.d -------------------------------------------------------------------------------- /data/wasd/functions/zprivate/atan2.mcfunction: -------------------------------------------------------------------------------- 1 | ## Remez Algorithm 2 | #a := min (|x|, |y|) / max (|x|, |y|) 3 | #s := a * a 4 | #r := ((-0.0464964749 * s + 0.15931422) * s - 0.327622764) * s * a + a 5 | #if |y| > |x| then r := 1.57079637 - r 6 | #if x < 0 then r := 3.14159274 - r 7 | #if y < 0 then r := -r 8 | 9 | ## a 10 | scoreboard players operation #temp math = in math 11 | scoreboard players operation #temp1 math = in1 math 12 | execute if score #temp math matches ..-1 run scoreboard players operation #temp math *= #-1 constant 13 | execute if score #temp1 math matches ..-1 run scoreboard players operation #temp1 math *= #-1 constant 14 | scoreboard players operation #temp2 math = #temp math 15 | scoreboard players operation #temp2 math < #temp1 math 16 | scoreboard players operation #temp3 math = #temp math 17 | scoreboard players operation #temp3 math > #temp1 math 18 | scoreboard players operation #temp2 math *= #1000 constant 19 | scoreboard players operation #temp2 math /= #temp3 math 20 | ## s 21 | scoreboard players operation #temp3 math = #temp2 math 22 | scoreboard players operation #temp3 math *= #temp3 math 23 | scoreboard players operation #temp3 math /= #1000 constant 24 | ## r 25 | scoreboard players operation out math = #temp3 math 26 | scoreboard players operation out math *= #-46496 constant 27 | scoreboard players operation out math /= #100000 constant 28 | scoreboard players add out math 1593 29 | scoreboard players operation out math *= #temp3 math 30 | scoreboard players operation out math /= #1000 constant 31 | scoreboard players remove out math 3276 32 | scoreboard players operation out math *= #temp3 math 33 | scoreboard players operation out math /= #1000 constant 34 | scoreboard players operation out math *= #temp2 math 35 | scoreboard players operation out math /= #10000 constant 36 | scoreboard players operation out math += #temp2 math 37 | execute if score #temp1 math > #temp math run scoreboard players remove out math 1570 38 | execute if score #temp1 math > #temp math run scoreboard players operation out math *= #-1 constant 39 | execute if score in math matches ..-1 run scoreboard players remove out math 3141 40 | execute if score in math matches ..-1 run scoreboard players operation out math *= #-1 constant 41 | execute if score in1 math matches ..-1 run scoreboard players operation out math *= #-1 constant 42 | ## rad 2 deg 43 | scoreboard players operation out math *= #57295 constant 44 | scoreboard players operation out math /= #1000000 constant -------------------------------------------------------------------------------- /data/wasd/functions/zprivate/calc_range.mcfunction: -------------------------------------------------------------------------------- 1 | ## debouncing rotation 2 | scoreboard players operation .ry wasd = @s wasd 3 | execute store result score @s wasd run data get entity @s Rotation[0] 1.0 4 | 5 | ## dir = atan2(Motion[0],Motion[2]) + Rotation[0] 6 | scoreboard players operation in math = .z wasd 7 | scoreboard players operation in1 math = .x wasd 8 | function wasd:zprivate/atan2 9 | scoreboard players operation .dir wasd = out math 10 | scoreboard players operation .dir wasd += .ry wasd 11 | 12 | ## Map angle to the range 0..360 13 | scoreboard players operation .dir wasd %= #360 constant 14 | 15 | ## WASD based on dir angle ranges 16 | execute if score .dir wasd matches 23..157 run scoreboard players set .a wasd 1 17 | execute if score .dir wasd matches 112..248 run scoreboard players set .s wasd 1 18 | execute if score .dir wasd matches 203..337 run scoreboard players set .d wasd 1 19 | execute if score .dir wasd matches 293..360 run scoreboard players set .w wasd 1 20 | execute if score .dir wasd matches 0..67 run scoreboard players set .w wasd 1 21 | -------------------------------------------------------------------------------- /data/wasd/functions/zprivate/input.mcfunction: -------------------------------------------------------------------------------- 1 | scoreboard players set .w wasd 0 2 | scoreboard players set .a wasd 0 3 | scoreboard players set .s wasd 0 4 | scoreboard players set .d wasd 0 5 | scoreboard players set .dir wasd 0 6 | execute if score .z wasd matches 0 if score .x wasd matches 0 run scoreboard players set .dir wasd -999 7 | execute unless score .dir wasd matches -999 run function wasd:zprivate/calc_range 8 | execute if score in wasd matches 1 run function wasd:zprivate/apply_tags -------------------------------------------------------------------------------- /data/wasd/predicates/is_mounted.json: -------------------------------------------------------------------------------- 1 | { 2 | "condition": "minecraft:entity_properties", 3 | "entity": "this", 4 | "predicate": { 5 | "vehicle": {} 6 | } 7 | } -------------------------------------------------------------------------------- /data/wasd/predicates/is_wasder.json: -------------------------------------------------------------------------------- 1 | { 2 | "condition": "minecraft:entity_properties", 3 | "entity": "this", 4 | "predicate": { 5 | "vehicle": {} 6 | } 7 | } -------------------------------------------------------------------------------- /pack.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "pack": { 3 | "pack_format": 7, 4 | "description": "Test" 5 | } 6 | } --------------------------------------------------------------------------------