Bedrock Wiki
  • Discord
  • Contribute
  • bedrock.dev
  • MS Learn
Beginner's Guide
  • Guide
    • 1. Introduction
      guide
    • 2. Add-Ons Explained
    • 3. Software & Preparation
    • 4. Project Setup
    • 5. Create a Custom Item
    • 6. Create a Custom Entity
    • 7. Blockbench: Modeling, Texturing & Animating
    • 8. Adding a Loot Table, Spawn Rule & Crafting Recipe
  • Extra
    • a. Understanding JSON
    • b. Download Example Packs
    • c. Troubleshooting
      help
    • d. Advanced Manifest
    • e. Format Versions
    • f. Project Setup Android
Animation Controllers
  • Intro to Animation Controllers
    guide
  • Entity Commands
  • AFK Detector
  • Death Commands
  • Molang into Scoreboard
  • Respawn Commands
Blocks
  • General
    • Intro to Blocks
      guide
    • Block Components
    • Block Tags
    • Block States
    • Block Traits
    • Block Permutations
    • Block Events
      Scripts
    • Block Event Migration
      help
    • Blocks as Items
    • Troubleshooting Blocks
      help
  • Visuals
    • Block Culling
    • Block Models
      guide
    • Block Texture Animation
    • Block Texture Variation
    • Block Tinting
  • Tutorials
    • Applying Constant Effects
      Scripts
    • Avoiding State Limit
    • Fake Blocks
    • Ore Loot Tables
      Scripts
    • Precise Interaction
      Scripts
    • Precise Rotation
      Scripts
    • Rotatable Blocks
  • Vanilla Re-Creations
    • Custom Crops
      Scripts
    • Custom Glass
    • Custom Glazed Terracotta
    • Custom Trapdoors
      Scripts
  • Documentation
    • Block Format History
    • Block Shapes
    • Block Sounds
    • Vanilla Block Models
Commands
  • General
    • Intro to Command Blocks
    • Functions
    • Block States
    • Coordinate System
    • NBT Commands
    • Scoreboard Operations
    • Understanding Selectors
  • Commands
    • Damage
    • Execute
    • Playanimation
    • Playsound
  • On Event Systems
    • On Player First Join
    • On Player Join
    • On Player Leave
    • On Player Death
    • On Player Respawn
    • On First World Load
  • Scoreboard Systems
    • Entity Counter
    • Scoreboard Timers
    • Comparing And Retrieving Scores
  • Techniques
    • Execute Logic Gates
    • MBE - Max's Block Entity
    • FMBE - A New Way to Create Display Entities
    • Look Detection
    • Movement Detections
    • Orbital Camera
  • Useful Creations
    • Custom Crafter
    • Multiplayer Position Rearrangement
      function
Concepts
  • contents.json
  • Emojis & Symbols
  • Molang
  • Namespaces
  • Overwriting Assets
  • Raw Text
  • Shaders
  • Sounds
  • Subpacks
  • Text and Localization
  • Texture Atlases
  • textures_list.json
Documentation
  • Shared Constructs
  • Advanced Molang
  • File Types
  • Fog IDs
  • Material Configuration Description
  • Menu Categories
  • Molang Queries
  • Pack Folder Structure
  • Sound Definitions
  • Vanilla Materials
Entities
  • General
    • Intro to Entities BP
      guide
    • Intro to Entities RP
      guide
    • Troubleshooting Entities
      help
    • Entity Events
    • Entity Properties
    • NPC Dialogues
    • Render Controllers
    • Spawn Rules
  • Tutorials
    • Convert Points Between Any Space (World, Entity, Bones)
    • Creating Boats
    • Detecting Other Entities
    • Disabling Team Damage
    • Dummy Entities
    • Entity Attacks
    • Entity Holds Item
    • Entity Movement
    • Entity Timers
    • Flying Entities
    • Introduction to AOE Clouds
    • Invulnerable Entities
    • Look at Entity
    • Sleeping Entities
    • Solid Entities
    • Spawning Tamed Entities
      Scripts
    • Village Mechanic
  • Documentation
    • Dummy Components
    • Non-Mob Runtime Identifiers
    • Projectiles
    • Runtime Identifiers
    • Vanilla Usage Components
    • Vanilla Usage Spawn Rules
Items
  • General
    • Intro to Items
      guide
    • Item Components
    • Item Tags
    • Item Events
      Scripts
    • Item Event Migration
      help
    • Troubleshooting Items
      help
  • Tutorials
    • Custom Armor
    • Custom Food
      Scripts
    • Custom Pottery Sherds
    • Custom Weapons
    • Equipment-Based Commands
    • High Resolution Items
    • Spawning Items
    • Throwable Items
  • Documentation
    • Enchantments
    • Attachables
    • Item Format History
    • Numerical Item IDs
    • Vanilla Item Identifiers
    • Vanilla Usage Components
JSON UI
  • General
    • Intro to JSON UI
      guide
    • Best Practices
      guide
  • Tutorials
    • Adding HUD Elements
    • Aseprite Animations
    • Buttons and Toggles
    • Modifying Server Forms
    • Preserve Title Texts
    • String to Number
  • Documentation
    • JSON UI Documentation
Loot, Recipes & Trading
  • General
    • Trading Behavior
  • Documentation
    • Loot Tables
    • Trade Tables
    • Recipes
    • Item Functions
  • Tutorials
    • Randomized Structure Loot
Meta
  • Add-On Performance
  • Style Guide
  • Useful Links
  • Using Schemas
  • Version Control
  • Q&A
    • Blocks and Items Q&A 2024/08/30
    • Deferred Technical Preview Q&A 2024/02/23
    • GameTest Q&A 2021/08/06
    • Scripting and Editor Q&A 2023/09/22
    • World Generation Q&A 2024/11/15
NBT
  • General
    • .mcstructure
  • Tutorials
    • Experiments in Education Edition
    • Extending Structure Limits
  • NBT in Depth
    • About NBT (Named Binary Tag)
    • NBT Libraries
    • Reading NBT Example
Particles
  • General
    • Intro to Particles
      guide
  • Tutorials
    • Disabling Particles
  • Documentation
    • Vanilla Particles
Scripting
  • General
    • Intro to Scripting
    • What is Script API?
    • API Modules
  • Tutorials
    • Block Placement Prevention
    • GameTests
    • Script Core Features
    • Script Forms
    • Script Requests API
    • Simple Chat Commands
  • Documentation
    • Engine Environment
    • Script Resources
    • Script Watchdog
    • Troubleshooting JavaScript
    • TypeScript
Servers
  • Software
    • Bedrock Server Software
  • Protocols
    • Bedrock Protocol
    • NetherNet Protocol
    • RakNet Protocol
Visuals
  • General
    • Introduction to Entity Visuals
      guide
    • Bedrock Modeling
    • Custom Death Animations
    • Effects in Animations
    • Material Creations
    • Materials
    • Math-Based Animations
    • Skin Packs
  • Tutorials
    • Entity Texture Animation
    • Glowing Entity Texture
    • Hurt Animations
    • Leash Position
    • Player Geometry
    • Remove Entity Shadows
    • Retexturing Spawn Eggs
  • Ideas
    • Structure Presentation
World Generation
  • General
    • Intro to World Generation
      guide
    • Biomes
      guide
    • Feature Types
    • Jigsaw Structures
  • Tutorials
    • Block Conditions for Features
    • Generating Custom Ores
    • Generating Custom Structures
    • Generating Patches
    • Heightmap Noise
  • Documentation
    • Biome Tags

Multiplayer Position Rearrangement

function
Multiplayer Position Rearrangement
  • Introduction
  • Steps Involved in This Method
  • Functions
  • Tick JSON
  • Folder Structure
  • Download Function Pack

Introduction ​

Sourced by the Bedrock Commands Community (BCC) Discord

Multiplayer Position Rearrangement function, or more accurately Multiplayer Position Derangement function, created by @ZheaEvyline, allows you to randomly relocate all selected targets among each other, ensuring no target remains in its original position.

A derangement is a permutation of 'N' elements where no element appears in its original position.

For example, if Player1 was at (0, 0, 1), Player2 at (0, 0, 2), and Player3 at (0, 0, 3), Player1 can only be relocated to (0, 0, 2), or (0, 0, 3). The same rule applies to all other players.


Key Features of this Function Pack:

  1. Guaranteed derangement in a single game-tick.
  2. Minimal number of iterations (repetitions/loops).
  3. Cross Dimensional Compatibility.

This function pack is designed to support an unlimited number of targets. However, due to Bedrock limitations, it will halt once the 10,000 function execution limit is reached.

For instance, deranging the positions of 100 targets requires only 4-6 iterations, with 7 commands executed during initialization and 9 per iteration. This totals approximately 60 commands, significantly below the function limit.


The number of iterations increases proportionally with the number of elements.

For reference, here is the number of derangements possible for elements ranging from 1 to 10:

Number of Elements (N)Number of Derangements Possible (D(N))
10
21
32
49
544
6265
71,854
814,833
9133,496
101,334,961

The number of derangement possibilities increases rapidly as the number of elements grows.

Steps Involved in This Method ​

  1. Relocate each target to the position of a random one (other than its original position).
  2. If multiple targets are relocated to the same position, assign it to one of them and repeat the process for the remaining targets.
  3. If final target is left with no available position except its original, relocate the target in it's current position to it's original position, assigning the now freed position to the final target.

Example Visualization:

Position of Five Players Being Deranged

Functions ​

An ID system is required to index the position of all targets from 1 to N, allowing us to track the original position of each target. We will run this file in the tick.json to automatically assign the IDs.

BP/functions/wiki/scoreboard/players/id.mcfunction
yaml
## Register New Players to ID Objective
scoreboard players add @a wiki:id 0

## Create New ID
execute if entity @a[scores={wiki:id=0}] run scoreboard players add .Total wiki:id 1

## Assign the New ID
scoreboard players operation @r[scores={wiki:id=0}] wiki:id = .Total wiki:id
1
2
3
4
5
6
7
8

This is the function you run (once) each time you need to derange the positions of all targets:

  • /function wiki/derange_position/initiate
BP/functions/wiki/derange_position/initiate.mcfunction
yaml
## Summon Position Marker
execute at @a run summon armor_stand "wiki:position_marker" ~~~

## Save Original Position to Ignore
execute as @a at @s run scoreboard players operation @e[type=armor_stand,name="wiki:position_marker",r=0.01,c=1] wiki:id = @s wiki:id

## Initiate Position Derangement Process for All Targets
function wiki/derange_position/process

## Run Process One Last Time if Final Player Has a Valid Position Available
execute if score .Players.NotAllocated wiki:count matches 1 unless score @a[tag=!wiki:pos.allocated,c=1] wiki:id = @e[type=armor_stand,name="wiki:position_marker",c=1] wiki:id run function wiki/derange_position/process

## Resolve Collision if Final Player Has No Valid Position Available
### relocate the allocated player to their colliding player's original position to free their position for the colliding player
execute as @a[tag=!wiki:pos.allocated] at @s run tp @r[tag=wiki:pos.allocated,r=0.01] @e[type=armor_stand,name="wiki:position_marker",c=1]
### remove colliding player's position marker and tag
kill @e[type=armor_stand,name="wiki:position_marker"]
tag @a[tag=wiki:pos.allocated] remove wiki:pos.allocated
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

In case a single target is left with no available position except its original, the final 3 commands will resolve the collision. We call it a collision because when this occurs, the target will be at the allocated position of another target.


The actual randomized derangement process will be performed by this function below:

BP/functions/wiki/derange_position/process.mcfunction
yaml
## Move to a Different Position
execute as @a[tag=!wiki:pos.allocated] at @s run function wiki/derange_position/teleport

## If Returned to Original Position: Move Again
execute as @a[tag=!wiki:pos.allocated] at @s if score @s wiki:id = @e[type=armor_stand,name="wiki:position_marker",r=0.01,c=1] wiki:id run function wiki/derange_position/teleport

## Add Tag to Ignore Players with a Position Allocated
execute as @e[type=armor_stand,name="wiki:position_marker"] at @s run tag @a[tag=!wiki:pos.allocated,r=0.01,c=1] add wiki:pos.allocated

## Remove Allocated Position Markers
execute as @a[tag=wiki:pos.allocated] at @s run kill @e[type=armor_stand,name="wiki:position_marker",r=0.01,c=1]


# ENTITY COUNTER

## Get Player Count of Players Without a Position Allocated
scoreboard players set .Players.NotAllocated wiki:count 0
execute as @a[tag=!wiki:pos.allocated] run scoreboard players add .Players.NotAllocated wiki:count 1

## If 2+ Players Are Not Allocated a Position: Loop Function
execute if score .Players.NotAllocated wiki:count matches 2.. run function wiki/derange_position/process
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

  • ❌️ tp @s @r[type=armor_stand,name="wiki:position_marker",rm=0.01]

Directly using this command to teleport to a new position only works within the current dimension. Therefore, instead of that, we use the following three-command function for cross-dimensional compatibility:

BP/functions/wiki/derange_position/teleport.mcfunction
yaml
tag @e[type=armor_stand,name="wiki:position_marker",r=0.01] add wiki:pos.ignored
tp @s @r[type=armor_stand,name="wiki:position_marker",tag=!wiki:pos.ignored]
tag @e remove wiki:pos.ignored
1
2
3

Now, for our functions to actually work, we will need to add the following objectives on our world:

BP/functions/scoreboard/objectives/add_all.mcfunction
yaml
scoreboard objectives add wiki:wiki:id dummy
scoreboard objectives add wiki:wiki:count dummy
1
2

If you wish to add the objectives automatically as soon as you load the world, you may create the function file below:

BP/functions/event/worlds/on_initialise.mcfunction
yaml
## Initialisation
### Add objective
scoreboard objectives add wiki:world dummy
### Register to objective
scoreboard players add .Initialised wiki:world 0

## Commands to Execute
execute if score .Initialised wiki:world matches 0 run function wiki/scoreboard/objectives/add_all

## Mark As Initialised
scoreboard players set .Initialised wiki:world 1
1
2
3
4
5
6
7
8
9
10
11

Tick JSON ​

Finally, create your tick.json file:

BP/functions/tick.json
json
{
  "values": [
    "wiki/event/worlds/on_initialise",
    "wiki/scoreboard/players/id"
  ]
}
1
2
3
4
5
6

Folder Structure ​

            • 📝id.mcfunction
            • 📝add_all.mcfunction
            • 📝on_initialise.mcfunction
          • 📝initiate.mcfunction
          • 📝process.mcfunction
          • 📝teleport.mcfunction
      • 📝tick.json
    • 📝manifest.json
    • 🖼️pack_icon.png

Download Function Pack ​

For convenience, you can download the .mcpack for the Function Pack here:

Download

Simply activate the pack on your world and run once (each time you need) the following command in multiplayer:

yaml
/function wiki/derange_position/initiate
1

Contributors

Edit Multiplayer Position Rearrangement on GitHub

Bedrock Wiki by Bedrock OSS

"Minecraft" is a trademark of Mojang AB.

Bedrock OSS, Bedrock Wiki and bedrock.dev are not affiliated in any way with Microsoft or Mojang AB.

  • Privacy Policy
  • Join our Discord
  • Learn how to Contribute
  • Visit our Repository