Download CPU Command Block Addon v0.0.2 Beta. (Script) (Windows 10 / Android) Now with Keyboard Support! (Download Fixed)) - Minecraft PE Addons
MC: CPU Command Block Addon v0.0.2 Beta. (Script) (Windows 10 / Android) Now with Keyboard Support! (Download Fixed))
Category:Minecraft PE Mods & Addons  / Minecraft PE Addons
Viewed: 1140 - Published at: 5 years ago

Description:

This addon is intended for developers, map makers, players and those willing to use Minecraft as an educational tool. It adds Numbered Blocks and a new kind of command block packed with many enhancements to the game. This new command block is called CPU and is capable of running multiple commands per line, parsing and executing mathematical expressions, reading and placing sequences of Numbered Blocks in the world, among other things. This addon requires the experimental Scripting API (currently only available for Windows 10, and on Android using latest version of Blocklauncher).

Developer: Kodexky.
Twitter:@kodexky

How It Works:

Numbered Blocks:

These are orientation aware and will rotate themselves once placed in the world according to the player’s facing direction. They can be crafted by putting a Cobblestone block in a Stonecutter. They can also be obtained using this command:

    /give @p cpu:number_0_west

Just replace the 0 with your desired number. If you need to rotate a number once placed just touch it (right click or short touch) with a Wooden Stick or with any Sword.

CPU Command Block:

CPU blocks can only be obtained using this command:

    /give @p cpu:cpu

CPUs have many more functions than the standard Command block. Once placed in the world the CPU will generate a name for itself. This name can be used later for relaying commands remotely to the CPU. When there is no other CPU in the world the 1st one will name itself “foo”. Every CPU after that will take an unique random name in the form “c-????”, where ???? will be replaced by hexadecimal characters (0-9, a-f). This initial name can be changed from the CPU interface.

CPUs can be activated and manipulated remotely or from their own User Interface (UI). You can enter the CPU UI the same way that you would use to rotate a number (touching it with a stick or a sword). To manipulate a CPU remotely you’ll have to use this command from either the Chat or another command block:

    /tag @e[type=cpu:cpu,name=CPUNAME] add “COMMAND”

You’ll have to replace CPUNAME and COMMAND as necessary.

The most basic enhancement offered by the CPU is the ability to sequentially execute multiple commands written on the same line. This is accomplished by separating all commands using two or more consecutive semi-colons (;;, ;;;, etc…). For example:

    /tag @e[type=cpu:cpu,name=foo] add “/say Hi! I’m a working CPU.;; /say Let me give you a present!;; /give @a minecraft:gold_block”

When issuing commands to a CPU from the chat or another normal command block, if you want to include a double-quote (“) as part of your command and not as a delimiter you’ll have to escape it. In other words, you must precede it with a backslash like this \”. This is not necessary when entering commands on the CPU UI.
   

CPU Commands Storage and Custom CPU Commands:

The CPU can store single commands and command sequences in multiple Command Slots. This system allows reusing them and the development of complex programs. Each Command Slot has its own name and can contain command sequences of up to 16384 characters. There is also a list of special commands that only the CPUs can understand.

To store commands in a slot from the chat or from other command blocks you should use this command:

    /tag @e[type=cpu:cpu,name=CPUNAME] add “/store SLOTNAME COMMANDSEQUENCE”

To delete a slot use this command:

    /tag @e[type=cpu:cpu,name=CPUNAME] add “/remove SLOTNAME”

To delete all the currently stored slots use this command:

    /tag @e[type=cpu:cpu,name=CPUNAME] add “/removeall”

To list all currently stored Slots use this command:

    /tag @e[type=cpu:cpu,name=CPUNAME] add “/list”

To execute the command sequence stored in a Slot use this command:

    /tag @e[type=cpu:cpu,name=CPUNAME] add “/exec SLOTNAME”

The “/exec” and “/list” commands can execute or list any number of slots sequentially in this way: “/exec SLOTNAME0 SLOTNAME1 SLOTNAME2 …”. They also support the use of wildcards (“*” and “?”) like this:

    /tag @e[type=cpu:cpu,name=CPUNAME] add “/exec a*”         — Executes all slots with their names starting with an “a”.
    /tag @e[type=cpu:cpu,name=CPUNAME] add “/exec a?”         — Executes all slots with their names starting with an “a” plus 1 extra character.
    /tag @e[type=cpu:cpu,name=CPUNAME] add “/exec a??”        — Executes all slots with their names starting with an “a” plus 2 extra characters.
    /tag @e[type=cpu:cpu,name=CPUNAME] add “/list _def a*”    — Lists the “_def” slot and all the slots with their names starting with an “a”.

The CPU names and Command Slots names share the same naming conventions. Names can contain up to 8 letters, numbers, hyphens (-) or underscores (_). If you wish to rename a CPU remotely use this command:

    /tag @e[type=cpu:cpu,name=CPUNAME] add “/rename NEWCPUNAME”

One extra improvement over standard command blocks is that CPUs cannot be destroyed by hitting them. To destroy a CPU you’ll have to enter its UI an click the button labeled “Kill me”. To avoid accidental destruction, this button will have to be clicked 3 times. If you want to destroy a CPU remotely you can use this command:

    /tag @e[type=cpu:cpu,name=CPUNAME] add “/killme”

Math Parser:

The CPU includes a math parser provided by the mathjs javascript library (https://mathjs.org) which allows it to execute complex operations. To perform an operation you’ll have to precede it with 2 slashes (//), and assign its result to a variable. To perform multiple operations on the same // command you’ll have to separate them using a single semi-colon. After that, you can use any variable value within other commands by enclosing the variable name like this “@`VARNAME`”. Here is an example:

    /tag @e[type=cpu:cpu,name=foo] add “// a=2; b=3; c=a*b ;; /say The result of multiplying @`a` by @`b` is @`c`”

The previous command will print this line to the chat:

    [foo]: The result of multiplying 2 by 3 is 6

All variable values are persistent and will remain declared between world loads. For this purpose the CPU uses a special Command Slot called “__SCOPE__”. This Slot is not accessible from the UI, but can be read using the “/list” command.

It’s important to mention that this addon uses a patched version of the mathjs library. In this version variables don’t need to be initialized before use. Any undeclared variable will have a default value of 0. This allows expression like “//a= a + 1” to work without throwing an error. Keep in mind that this patch may cause some strange behaviors in the parser.

If you want to remotely clear all currently assigned variables you can use the command “/reset”:

    /tag @e[type=cpu:cpu,name=foo] add “/reset”

The “/removeall” command also clears all currently assigned variables.

For more information about the operations syntax and available functions on mathjs please refer to “https://mathjs.org/docs/expressions/syntax.html” and “https://mathjs.org/docs/reference/functions.html“.

Custom Math Parser Functions:

This addon also expands the mathjs parser with custom functions that can be used in operations to enable interaction between the parser and the world. Let’s check them out.

pos(POSITION)
This function returns minecraft xyz location in an array ([x,y,z]). POSITION can be omitted, in that cases it will return the CPU location. POSITION can also be an string with a location in standard minecraft syntax (ie: “pos(‘~~~’)”, “pos(‘~ ~ ~’)”, “pos(‘~1~-1~1’)”, “pos(‘~1 0 0’)”, etc). For convenience POSITION can also be an array or an object of either numbers or strings (ie: “pos([0,0,0])”, “pos([‘~’,’~1′,0])”, “pos({x:0,y:0,z:0})”, “pos({x:’~’,y:’~1′,z:0})” ). Only objects with x,y and z properties will be recognized.

getnum(POSITION)
This function will return the value of a continuous Numbered Blocks sequence located at POSITION. It uses the same POSITION values available for the pos() function. The POSITION location should be the least significant number of the sequence (To read 2019 its POSITION should be the location of the 9 block). The orientation of the sequence will be taken from the block at POSITION, it doesn’t matter if the orientation of the other blocks in the sequence is different. This function will consider a sequence finished after finding the first non Numbered Block.

setnum(POSITION, VALUE, STYLE)
This function will place VALUE as a sequence of Numbered Blocks at POSITION. There must already be a Numbered Block at POSITION, for the orientation of the sequence will be the same of that block. The STYLE parameter is an optional string that allows to control decimals precision, whether the VALUE decimals will be rounded or truncated, and whether the new Numbered Blocks sequence length will be restricted to the one already existing in the world or if it will be unbounded.

The syntax of STYLE is as follows:

  • A numeric value from 0 to 16 for the decimals precision. If omitted defaults to showing as many decimals as the original VALUE.
  • The letter “r” indicates the decimals will be (r)ounded to the precision amount. If omitted decimals will be truncated instead of rounded.
  • The letter “u” indicates the Numbered Blocks sequence is (u)nbound and will be as long a needed to express the VALUE . If omitted the sequence length will be restricted to the length of the sequence already in place. When “u” is omitted and VALUE is too big for the available space it will fill the sequence with the “-” character. When omitted and VALUE is smaller than the available space it will fill the remainder blocks with 0.

//a=10.0005; setnum(‘~~1~’, a)         — On a POSITION with 8 Numbered Blocks in sequence it will place “010.0005”.
    //a=10.0005; setnum(‘~~1~’, a)         — On a POSITION with only 3 Numbered Blocks in sequence it will place “—“.
    //a=10.0005; setnum(‘~~1~’, a, ‘u’)    — On a POSITION with only 3 Numbered Blocks in sequence it will place “10.0005”.
    //a=10.0005; setnum(‘~~1~’, a, ‘u’)    — On a POSITION with 7 or more Numbered Blocks in sequence it will place “10.0005”.
    //a=10.0005; setnum(‘~~1~’, a, ‘3r’)   — On a POSITION with 7 Numbered Blocks in sequence will place “10.001”.
    //a=10.0005; setnum(‘~~1~’, a, 3)      — On a POSITION with 7 Numbered Blocks in sequence will place “10.000”.
    //a=10.0005; setnum(‘~~1~’, a, 0)      — On a POSITION with 2 Numbered Blocks in sequence will place “10”.

setblock(POSITION, BLOCKNAME, DATAVALUE)

This function works like the regular /setblock command. The only difference is that it can be used directly inside operations. There is a good example of the utility of this function in the Demo World provided in the downloads section of this article.

    //setblock(‘~~1~’,’emerald_block’);
    //loc=pos(‘~~1~’); block=’dirt’; setblock(loc, block);

getblock(POSITION)
This function gets the block id at POSITION inside an object, it also gets its block state properties if present.

    //setblock(‘~~1~’,’dirt’, 1); a=getblock(‘~~1~’);; /say @`a`   — This will output to the chat: “{“id”:”minecraft:dirt”,”dirt_type”:”coarse”}”

exec(‘SLOTNAME’)
This function works like the /exec command. This allows the conditional execution of Command Slots. To take advantage of this function you’ll have to use a ternary conditional like this:

    //a==0 ? exec(‘a00’) : exec(‘b00 b01’);;
    //a==0 ? exec(‘a00’) : exec(‘b??’);;
    //a==0 ? exec(‘a00’) : exec(‘b*’);;

When the condition expressed before the “?” character is true, the expression after the “?” will be executed. Otherwise the expression after the “:” will be executed.

moveme(‘POSITION’)
This function will teleport the CPU to POSITION.

Variable Substitution:

    The CPU allows to dynamically replace variables for their values in commands using this syntax “@`VARNAME`”. Note that the enclosing character is a backtick (“`”), this character can be found in OSK as the alternate character for the tilde (“~”). If VARNAME is an array with 3 values it will be recognized as a position and replaced with its 3 values separated by spaces. If VARNAME is an object, it will be replaced with its stringifyed version. The variable substitution will execute in all commands except “/store”.

        //a=’emerald_block’; b=pos(‘~~1~’);; /setblock @`b` @`a`;;   — This command will place an Emerald Block directly above the CPU.
        //a={id: ‘asd’, b: ‘dfg’};; /say @`a` ‘@`a.id`’ ‘@`a.b`’;;   — This will print “{“id”:”asd”,”b”:”dfg”} ‘asd’ ‘dfg'” to the chat.
        //a=[0,1,2];; /say Position @`a`;;    — This will print “Position 0 1 2” to the chat.

    Inside operations, all variable naming conventions of the mathjs library are valid. Please keep in mind that the old syntax (“@=VARNAME”) from version 0.0.1 has been deprecated and is no longer valid.

    Redstone Signal Awareness:

    CPUs are sensible to redstone signals in their immediate surroundings.

    When a CPU receives a redstone signal it will execute the commands stored in the “_def” slot. This default slot cannot be completely deleted. If you try to remove it, its contents will be erased but the slot will remain.

    The redstone signal strength will be stored in a variable named “RS” and can be used in operations.

    There are some peculiarities for the way a CPU reacts to redstone. Right now CPU Blocks can only react to signals in direct contact with them (x+-1,y+-1,z+-1), thCPU Demo Worldey are sensible to all normal signal sources at those positions except for powered blocks (ie: a dirt block powered by a button), and Jukeboxes playing a disc.

    CPUs can only read real signal strength in Redstone Wire, Pressure Plates and Daylight Detectors, all other sources will be read as a full signal (15), even for directly attached Comparators. The only way to read the real Comparator output signal is to place a redstone wire between the Comparator and the CPU.

    CPU User Interface:

    The CPU UI is pretty much self-explanatory. This version features an On Screen Keyboard (OSK) and a basic physical keyboard support. Due to limitations in the addons experimental UI system the keyboard layout is restricted to the standard US/English one. Both the OSK and the physical keyboard share the same layout.

    All keys have a basic auto-repeat function active. The OSK also features some helper keys displayed on both sides of the keyboard for easier and faster command input.

    When using the UI these keys have especial behaviors:
    The “Esc” key will exit from the editor window to the main UI window without saving any changes to the content. This key also closes the main CPU UI window.
    The “Enter” key will save the editor content and exit to the main CPU UI window.
    The “Tab” key will change the focus between the available text edit boxes.
       

    Demo CPU Program Function:

    This addon provides some CPU demo programs as examples. To test these CPU programs you’ll have to enter one of these commands to the chat:

        /function cpu/demo/sphere
        /function cpu/demo/circle
        /function cpu/demo/walker

    These commands will setup a CPU with same name as the function (A CPU named “sphere” for the sphere function…) with the necessary commands while deleting all previous Command Slots stored in that CPU. You can also test these programs in the attached Demo World.

    Future Improvements:

    Please keep in mind that this is an early beta and a proof of concept. It’s my intention to keep improving this addon in the future. Here is a list of currently planned features and improvements:

    • Add a /clone command to allow CPUs replication.
    • Add Repeat/Impulse functionality like the regular command block.
    • Add a “Delay in ticks” control to the UI like the regular the command block.
    • Add in game help and documentation to the UI.
    • Make the CPU execution log persistent and active while outside the UI.
    • Tweak and enhance the UI activation method.
    • Add extra math symbols as blocks.
    • Add debugging options.
    • Add the sphere demo program as a custom parser function.
    • Add extra WorldEdit functionality as custom parser functions.
    • Implement fully functional scrollbars.
    • Add a custom function for iterating loops.
    • Add dialogs to request user input.
    • Add a monitor entity to show data from the CPUs.
    • Add the ability to directly output data to the User Interface.

    Feedback and Support:

    If you have a bug report, want to make a suggestion, have a feature request, or just want to provide feedback, please contact me at my twitter: @kodexky

    Also, if you want to keep informed about changes and new releases of this addon please follow me there.

    Installation

    • Download the mcaddon file and open it.
    • Apply the pack to a world.
    • Enable “Experimental Gameplay” in the world settings.
    • Create the world.

    DOWNLOAD:

    TAGS :

    Reference: mcpedl.com