Minecraft Data Packs / Tool

Lib.Random (Random Number Generator) Minecraft Developer Library.

  • check_circle Functions
  • 3,020 views, 1 today
  • 86 downloads, 0 today
  • 3
  • 2
grizillar's Avatar grizillar
Level 36 : Artisan Procrastinator
8

Lib.Random (Random Number Generator) Minecraft Developer Library.



Lib.Random (also Random Class)is Minecraft new way to generate a random chance by function commands. For someone who already learning code, Random Class is almost the same as Java.util.Random in Java or Random in Python. The main objective of this data pack is to create a number from your range of numbers.

Documents
Variable
NameTypeDisplay NameNote
randomdummy--

Function
FunctionDescriptionTargetCommandCommand Comment
random:next/xSet score random randomly from the range 1 to x.@s/function random:next/xreplace x by your number (1-100)
random:resetReset random entities.-/function random:reset
random:createCreate random entities.-/function random:create
random:setupCreate "random" variable from the scoreboard.-/function random:setupalready create on import

Note: random:reset and random:create are part functions. They are no need to use for the normal circumstance.





Tutorials and Guides
This data pack, the target of the random is @s which mean you can target your own entity. If you just type command /function random:next/xfor example:
/function random:next/10When you set scoreboard random as sidebar, you will see a random number generated randomly.
However, if you put the previous command in command block, it definitely not work because the command block has no target as @s. What you need to do is put execute command to dedicate the target so you need to type (in command block)
execute as <target> run function random:next/xfor example:
execute as @p run function random:next/69The random number will create in range 1 to 69 for the nearest play(@p).

To set random in another scoreboard variable, you just need to use equal operation in scoreboard command.
/scoreboard players operation @s <Your Scoreboard> = @s randomfor example:
/function random:next/10
/scoreboard players operation @s killPoint = @s random
The random number will create in range 1 to 10 and put into scoreboard killPoint instead. or adding point to your scoreboard by
/function random:next/20
/scoreboard players operation @s gold += @s random
The random number will create in range 1 to 20 and add into scoreboard gold.


There are many more ways to use. Just try to apply to your problem.


Installation
1. Put "lib.random" into <your save folder>/datapacks.
2a. If you are currently in your world, type command /reload2b. If you are not currently in your world, it will automatically be installed as you load your world. if not, do 2a.
3. If it has succussed, the text "rib.random imported" will appear in chat box.
Note: Data packs format is 5 and never test on another version so it should work well on 1.15 or later.

Usage
This is open-source data pack so use as your will. Just do not replicate and do not use for direct profiting.
CompatibilityMinecraft 1.15
toMinecraft 1.16
Tags

Create an account or sign in to comment.

Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome